Type Conversion in C

Type Conversion simply means that conversion from one type (data type) to another. There are two types of type conversion in C language.

  • Automatic or Implicit Conversion
  • Type Casting or Explicit Conversion

    1. Automatic or Implicit Conversion : When operands of different data types are used in an arithmetic expression, one of the operand data types will be converted to the type another operand. This conversation is taking place automatically during program execution that is called Automatic Type Conversation or Implicit Conversion.
    The order of this conversion is as follows :

    char --> int --> long int --> float --> double
    (low ranking)                          (high ranking)
    Example :
    int m=25
    float x=5.5, y;
    y=m*x; // The result obtained by Automatic Type Conversation which is converted int to float data types.

    2. Type Casting or Explicit Conversion : Type Casting or Explicit Conversion is used to overcome Automatic Conversation. The variable declared in specific data type can be converted into another data type.

    (type) expression
    (type) (expression)
    Example :
    int m=5;
    float y;
    y=(float)m/2; // The result obtained by Explicit Conversion which is converted int into float data types and get result y=2.5;

    Recommended Posts:

        1. Fundamental of C Language
        2. Keywords in C
        3. Data Types in C
        4. Operators in C
        5. Type Conversion in C
        6. Input/Output Functions in C
        7. C Program to Swap Two Numbers With or Without Temporary Variables
        8. Control Statements in C – if, else, switch
        9. Loop Control Statements in C | for, while, do-while loop
        10. Comparison Between for loop while loop and do-while loop
        11. Unconditional Control Transfer Statements in C
        12. C Program to Check Armstrong Number
        13. C Program to Generate Fibonacci Series
        14. C Program to Check Whether a Number is Prime or Not
        15. C Program to Convert Binary Number to Decimal
        16. C Program to Convert Decimal Number to Binary