Data Type:
As the name indicates data and type are two different words. Data type specifies to the computer the sort of data we are giving to it. The compiler knows about the variable by looking at its data type and allocates some properties.There are several data types supported by C, they are discussed below.
1. int:
int is used to declare a integer type variable. It allocates 2 bytes or 4 bytes of memory based on the compiler and the computer. So the range of this can be calculated by the formula:
-2^(n-1) to (2^(n-1))-1
where, n is the no of bytes allocated.
So the range is -32,768 to 32,767 for 2 bytes.
Eg: int sum_of_numbers;
2.Char:
char is used to represent a character type variable. It allocates 1 byte of memory based on the compiler and computer used. So the range of this data type will be from -128 to 127.Every character stored in a char data type is represented as an ASCII value. Each character you type on keyboard including special characters and non printable characters have a unique ASCII code allocated to them. Upper case letters (A to Z) have ASCII value ranging from 65 to 90 and lower case letters(a to z) have values ranging from 97 to 122. We also have ASCII values for numbers from 0 to 9 ranging from 48 to 57.
Now can you guess the ASCII value for C.
Yes, you are right its 67.
3.Float:
float is data type used to floating point numbers and real numbers. It allocates 4 bytes of memory. It stores up to 6 digits after the decimal point. The range can be calculated using the formula given above.
4.Double:
double is data type to again store floating point numbers with larger range. It allocates 8 bytes of memory and stores up to 12 digits after the decimal point.
5.Void:
void is considered a data type to store nothing, it does not allocate any memory in the computer.
Data type Qualifiers:
Data type qualifiers give a special freedom to select a specific range. Qualifiers are of two types sign and size. The qualifiers are
discussed below:
Sign Qualifiers:
1.Unsigned:
unsigned qualifier makes any data type to store non negative integers only. If you try to store negative number you will get unexpected results.
Eg: unsigned int a;
unsigned char b;
2.Signed:
signed qualifier makes data type to store both negative and non negative integers. By default all the data types are signed.
Eg: signed int a; is similar to int a;
Size Qualifiers:
1.Long:
long qualifier is used to tell the compiler or computer to allocate more memory. For example int allocates 2 bytes or 4 bytes of memory but long qualifier makes it to allocate 4 and 8 bytes respectively.
Eg: long int a;
2.Short:
short qualifier is used to tell the compiler or computer to allocate less memory, so in this way we use the memory only needed by us.
Eg: short int a;
Summary of all the data types discussed above and some more data types are shown below in the table:
Sign up here with your email

ConversionConversion EmoticonEmoticon