Data types in C:
C has different types of data types. The data type is determines how much space is occupied by variable in the storage disk.
Mainly there are two types those are Pre- defined and User Defined.
Basic data types: These are arithmetic data types Integer, Char, float and Double.
Enumerated Type: enum is the arithmetic type used to define variables used to assign certain discrete integer values throughout the program.
Void data type: Void means no value.
Derived Data types: Derived data type means these are defined by the programmer at the time of programming based on the requirement.
Arrays, pointers, structures and union.
Data Types in C:
|Char||1 byte||−128 to 127|
|signed char||1 byte||−128 to 127|
|unsigned char||1 byte||0 to 127|
|Short||2 byte||−32,768 to 32,767|
|signed short||2 byte||−32,768 to 32,767|
|unsigned short||2 byte||0 to 32,767|
|Int||2 byte||−32,768 to 32,767|
|signed int||2 byte||−32,768 to 32,767|
|unsigned int||2 byte||0 to 32,767|
|short int||2 byte||−32,768 to 32,767|
|signed short int||2 byte||−32,768 to 32,767|
|unsigned short int||2 byte||0 to 32,767|
|long int||4 byte|
|signed long int||4 byte|
|unsigned long int||4 byte|
|long double||10 byte|
The above shows the basic data types in c.
Note: If you want to know the exact size of the variable or a type use sizeof() operator .
Below program demonstrates how to use sizeof() operator in c and know the values of basic data types.
This is basic interview question for fresher use of sizeof() operator.
printf(“size of an integer: %d \n”,sizeof(int));
printf(“size of float: %d \n”,sizeof(float));
printf(“size of Character: %d \n”,sizeof(char));
printf(“size of double: %d \n”,sizeof(double));
Output is :
size of an integer:2
size of float: 4
size of Character:1
size of double: 8
Press Alt +f9 and then Ctrl+f9 to compile and run the program.
Out put of the above program is: