- In a C program, the programmer has to tell the system before, the type of numbers or characters he is using in his program. These specification of data is called data type.
- C language data types can be classified in to 3 types as shown in figure
Primary Data type:
|No||Data Type||Full form||Range of Values|
|1||char||Character||-128 to 127|
|2||int||Integer||-32768 to +32767|
|3||float||single precision floating point||3.4e-38 to 3.4e+38|
|4||double||Double precision floating point||1.7e-308 to 1.7e+308|
- void data type used in functions to specify the return value or the arguments.
- There are number of qualifiers such as short,long,signed,unsigned can be applied to these primary data types.
- The possible qualifiers for the basic type are shown in the table
- Each compiler is free to choose appropriate size for its own hardware with restrictions that short and int are atleast 16 bits and longs are atleast 32 bits and size of short < int < long.
- qualifier signed or unsigned may be applied to char or any integer.
- unsigned numbers are always positive or zero and obey the laws of arithmetic modulo 2n, where n is the number of bits in the type.For example char is 8 bits so unsigned char variables have values between 0 and 28 ie values between 0 and 255.
|Data Type||16 bit machine||32 bit machine|
|Char or Signed Char||1||-128 to 127||1||-128 to 127|
|Unsigned Char||1||0 to 255||1||0 to 255|
|Short int or Signed short int||1||-128 to 127||2||-32768 to 32767|
|unsigned short int||1||0 to 255||2||0 to 65535|
|int or Signed int||2||-32768 to 32767||4||-2147483648 to 2147483647|
|Unsigned int||2||0 to 65535||4||0 to 4294967295|
|Long int or Signed long int||4||-2147483648 to 2147483647||4||-2147483648 to 2147483647|
|Unsigned long int||4||0 to 4294967295||4||0 to 4294967295|
|Float||4||3.4e-38 to 3.4e+38||4||3.4e-38 to 3.4e+38|
|Double||8||1.7e-308 to 1.7e+308||8||1.7e-308 to 1.7e+308|
|Long Double||10||3.4e-4932 to 3.4e+4932||16|
- If we do not specify either signed or unsigned, most compiler will assume the type to be signed. so signed int x; can be written as int x;
- short and long can be used alone as type specifiers.
Short int x; can be wriiten as short x;
- signed and unsigned can also be used alone as type specifiers.
unsigned int x; can be wriiten as unsigned x;