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.

  1. What is the size of data?
  2. 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.

  1. Primitive/Basic data type
    There are basic 5 data type.
    1. int - integer : used to store whole numbers ( e.g. 1, 100, 500, 2343, 45666 )
    2. float - float : used to store real numbers ( e.g. 2.3, 5.3, 66.44, 544.5 )
    3. 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 )
    4. char - character : used to store single character ( e.g. 'A', 'c', '$', '+', 'D' )
    5. void - no value : used to represent that it has no value. Generally used for mentioning function return type when function has nothing to return.
       
  2. User defined data type
    User defined data type is built upon basic type.
    1. 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.
    2. 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.
      
    3. Union
      Union will be discussed separately in advanced topics of C.