CodesandTutorials
Next generation website theme is here (black, neon and white color) - Reduces eye strain and headache problems.
You are here - Home > Programming > C > Basics

Data Types


Description

Data type is classification of a particular type of data like integer, float, character, boolean etc. It is mainly classified in two types primary and seconday data types as shown in figure.

Primary Data Types

Character type:

  • Can store only single signed or unsigned character.
  • Both occupy 8 bit storage space, but their ranges are different.
  • For unsigned character its value range from 0 to 255 and for signed characters its from -128 to 127.
  • Declaration and initializing syntax: char <variable name>; and char <variable name> = '<single character>';
  • Eg: char value;
    char value = 'a';

Integer type:

  • Can store only whole numbers and fractional numbers are not allowed.
  • Divided into three classes short int, int and long int. And all these data types have two forms signed and unsigned.
  • Each data type memory size and ranges are different.
  • Declaration and initializing syntax: int <variable name>; and int <variable name> = <whole number>;
  • Eg: int a;
    int a = 2;
    short int b = 3;
    long int c = 4;

Float type

  • Can store real numbers with 6 digits precision.
  • Requires 4 byte of memory space and ranges from 3.4E�38 to 3.4E+38
  • Declaration and initializing syntax: float <variable name>; and float <variable name> = <real number>;
  • Eg: float percentage;
    float percentage = 49.21;

Double type

  • When precision of float data type is short, we go for double which can store larger value and precision.
  • Double requires 8 bytes and long doubel requires 10 bytes.
  • Declaration and initializing syntax: double <variable name>; and double <variable name> = <real number>;
  • Eg: double speed_rate;
    double speed_rate = 1349.213235644;

Void type

  • Void specifies it has no value.
  • Mainly used in functions to speicify it does not return any value from it.
  • Eg: void main()

Secondary Data Types

Following data types are disccused in upcoming points.

  • Array
  • Pointer
  • Structure
  • Union
  • Enum etc.

Tip Box

Choosing proper data type

Data types like long integer, double, long double are slower in arithmetic operations as they occupy more memory, making the program larger. So you should use smallest variable data type that is suitable for your program.


Advertisement





Terms of Use | Privacy Policy | Contact Us | Advertise
CodesandTutorials © 2014 All Rights Reserved