The data type is the data that will be accessed within the program. C language supports different data types, each data type may have predefined memory requirement and storage representation.
C programming language supports the following 4 classes of data types
|char, int, float, double||typedef||arrays, pointer, structures, union||void|
The bytes occupied by each of the primary data types are
|int||Integer Quantity||2 bytes||%d or %i|
|char||Single Character||1 byte||%c|
|float||Floating pointing no’s||4 bytes||%f or %g|
|double||Double precision floating pointing no’s||8 bytes||%ld|
[Note: All C language compiler supports the five fundamental data types called int, char, float, double and void.]
The primary data types are divided into the following.
|short int||insigned short int|
|long int||unsigned long int|
In C language Integers are the numbers with the supported range, usually, the integers occupy one word of storage typically 16 to 32 bits. The size of the integer depends upon the system.
Eg. If you use a 16-bit word length, the size can be limited from -32768 to +32767.
To get the exact size of a type or a variable on a particular platform, you can use the sizeof driver. The expression sizeof ( type) yields the storage size of the object or type in bytes. Following is an example to get the size of int type on any machine
Storage size for int : 4
Character Types in C language
Character is generally stored in 8 bits of the internal storage of the computer and a single character can be defined as a char data type.
|Type||Storage size||Value Range|
|char||1 byte||-128 to +127|
|unsigned char||1 byte||0 to 255|
In C language floating-point numbers are generally stored in 32 bits with 6 digits of precision. These numbers are defined by using the keywords float and double, whereas the double data type uses 64 bits with 14 digits of precision.
The following table gives you important points about standard floating-point types with storage sizes and value ranges and their precision:
|Type||Storage size||Range||Precision||Control String|
|float||4 bytes||3.4E-38 to 3.4E+38||6 decimal places||%f|
|double||8 bytes||1.7E-308 to 1.7E+308||15 decimal places||%lf|
|long double||10 bytes||3.4E-4932 to 1.1E+4932||19 decimal places||%lf|
The header file float.h defines macros that allow you to use these values and different details about the binary representation of real numbers in your programs.
The following example will print storage space taken by a float type and its range values:
Storage size for float : 4 Minimum float positive value: 1.175494E-38 Maximum float positive value: 3.402823E+38 Precision value: 6
The void is a null data type in the C programming language. This is generally specified with the function which has no arguments.
Type Qualifiers in C language
If you use a 16-bit word length, the size of the data type is limited to the specific range.
So in order to provide some control over the range of numbers and storage space of the type, some basic data types, basic data types can be argumented by using the data type qualifiers, they are,
short, long, signed, unsigned
The declaration of long and unsigned integers permits us to increase the range of values. The precedence of a signed declaration for an integer is essential as the default declaration assumes signed numbers.
|Type||size (bytes)||Range||Control String|
|char or signed char||1||-128 to 127||%c|
|unsigned char||1||0 to 255||%c|
|int or signed int||2||-32,768 to 32,767||%d or %i|
|unsigned int||2||0 to 65,535||%u|
|short int or signed short int||1||-128 ro 127||%d to %i|
|unsigned short int||1||0 to 255||%d to %i|
|long int or signed long int||4||-2,147,483,648 to 2,147,483,647||%ld|
|unsigned long int||4||0 to 4,294,967,295||%lu|