Data types indicate the which type of data stored in a variable.
The type of a variable determines how much space it occupies in storage.
In C, data types are classified in following types:
- Basic Data Type:
- Derived Data Type:
- Void Data Type:
- Enumeration Data Type:
Basic Data Types
- char – char defines a character used to store a single character.
Example: char ch = ‘a’;
- int – int is used to store integer numbers.
Example: int count = 5;
- float – float is used to define floating-point numbers with single precision.
Example: float x = 10.0f;
- double – double is used to define floating-point numbers with double precision.
Example: double num = 10.9999;
Different data types also have different value range. The storage size of basic data types changes according to 8 or 16 or 32 or 64-bit operating system.
The following table gives details of data types with there required storage size and value ranges according to 16-bit architecture:
|Type||Storage size (byte)||Value range|
|char||1||-128 to 127|
|signed char||1||-128 to 127|
|unsigned char||1||0 to 255|
|int||2||-32,768 to 32,767|
|signed int||2||-32,768 to 32,767|
|unsigned int||2||0 to 65,535|
|short int||2||−32,768 to 32,767|
|signed short int||2||−32,768 to 32,767|
|unsigned short int||2||0 to 65,535|
|long int||4||-2,147,483,648 to 2,147,483,647|
|long signed int||4||-2,147,483,648 to 2,147,483,647|
|long unsigned int||4||0 to 4,294,967,295|
|float||4||-3.4e38 to +3.4e38 (6 decimal precision)|
|double||8||-1.7e308 to +1.7e308 (15 decimal precision)|
|long double||10||-1.7e4932 to +1.7e4932 (19 decimal precision)|
Mainly, the primary data types are of three varieties, char int, and float. But how C programmer manages with only 3 data types. Fact is, They can derive many data types from these three types.
The primary data types could be of several types. Like a char could be unsigned-char (1 byte) or signed-char(1 byte) OR int could be short-int(2 bytes) or long-int (4 bytes).
Note: Now C allows the abbreviation of short int to short and of long int to long.
Integer signed and unsigned:
Above diagram shows int could be short int or long int. short int is also called as short and long int is also known as long. Now int can be signed int or unsigned int. There also short unsigned int and short signed int. By default short signed int is short int.
Same as short, long unsigned int and long signed int also exist. By default long signed int is long int.
Char, signed and unsigned:
Parallel to signed int and unsigned int, similarly there exist signed and unsigned char each are of 1 byte. Signed char is same as ordinary char. Signed char has ranged from -128 to +127. Unsigned char has ranged from 0 to 255.
Floats and Doubles:
Float occupies 4 bytes in memory. If this is insufficient then C offers a double data type that occupies 8 bytes in memory. If the situation demands beyond double data type, then there exists a long double data type which occupies 10 bytes in memory.
Derived Data Type
Derived data types include Pointer types, Array types, Structure types, Union types, Function types.
Enumeration Data Types
enum is a special data type that consists of the set of constants.
Void Data Types
Void is an empty data type that has no value.
A Void data type used with functions to return no value.
3 thoughts on “C Data Types”
why didnt you explain each type of data 🙁
Thanks for your valuable response, we would surely try to explain each datatype in details and also inform you regarding the same.