Data Type: Data Type specifies the type of data that can be stored in a variable and the number of bytes required to represent a type. Following are a few examples of data types used in C:
char: This is the most basic data type in C. It stores a single character and requires a single byte of memory in a majority of the compilers.
int: As the name suggests, an int variable is used to store an integer. This data type is used to store integer values.
float: Decimal numbers (numbers with floating point value) with single precision are stored in this data type.
double: It is used to store decimal numbers (numbers with floating point value) with double precision.
|Basic data types||Memory requirements|
|char||1 byte (8 bits)|
|int||4 bytes (32 bits)|
|float||4 bytes (32 bits)|
|double||8 bytes (64 bits) which means more significant figures and an exponent of large magnitude.|
int a = 40; // positive integer data type float b = 5.8967; // float data type char c = 'Z'; // char data type long d = 41657; // long positive integer data type
The above example should thus be written like this
int a,b; (or) int a; int b; a=7, b=4; printf("%d", a-b);
Now, what happens when the above-mentioned declaration statement is executed?
1) The compiler is informed that 'a' and 'b' are variables which can hold only integer values
2) It also allocates 4 bytes of memory for both 'a' and `b'