Why use data type ?

  1. Type: identifying & distinguishing qualities


    Each variable in program has a data type (or type for short)
    Each value (constant) has a data type (or type for short)

  2. Variables and/or values of the same type can be combined "naturally" in operations such as +, -, * or /

    Example:
    
        int A;	- stores integer value
        int B;	- stores integer value
    
        A + B       - adding 2 integers is natural 
    

    This is the same situation as "adding apples and apples".

  3. Variables of the different types DO NOT mix "naturally" in operations such as +, -, * or /.

    Example:
    
        int A;	    - stores integer value
        float B;	    - stores floating point number
    
        A + B           - adding integer and float is not natural
    

    This is the same situation as "adding apples and oranges".

  4. Data type can help programmer write better (more correct) programs by disallowing operations on "uncompatible" values