C data types
Data type is C keyword that tells compiler what kind of variable we have declared.
Data type of variable gives two kind of information of variable data.
- What is the size of data?
- What is the type of data?
It helps compiler to reserve memory for variable and how to read and write them.
There are 2 categories of data types.
- Primitive/Basic data type
There are basic 5 data type.- int - integer : used to store whole numbers ( e.g. 1, 100, 500, 2343, 45666 )
- float - float : used to store real numbers ( e.g. 2.3, 5.3, 66.44, 544.5 )
- double - double-precision floating value : used to store real number with high precision of fractional part ( e.g 2.44445453, 5.4445453543, 4.45353453453, 45.453534534534 )
- char - character : used to store single character ( e.g. 'A', 'c', '$', '+', 'D' )
- void - no value : used to represent that it has no value. Generally used for mentioning function return type when function has nothing to return.
- User defined data type
User defined data type is built upon basic type.- Array
Array reprensts multiple countinous elements of given data type.
For example,int nums[10]; // Here 'nums' is an array of 10 elements of integer kind.
char name[12]; // Here 'name' is an array of 12 elements of character kind.
- Structure
Structure represents different kind of data type as single record.
For example,struct { int item_id, float item_value } item; // Here 'item' is structure having two members. // 'item_id' of integer type. // 'item_value' of floating type.
- Union
Union will be discussed separately in advanced topics of C.
- Array