Home Programming Fundamentals Using C Type Conversion in C Programming

Type Conversion in C Programming

19
0

While performing a mathematical operation in C programming, some times one data type is automatically converted and some times manually we have to convert it to another data type. This is called type conversion. The conversion is done only between those data types, where possible.

  1. Implicit type conversion : It can also be called as automatic type conversion. Normally it happens when an expression contains more then one data type. The operand at lower rank is converted to the corresponding higher rank data type.Now we will list data types from lower to higher rank :
    char, short
    int
    unsigned int
    long int
    unsigned long int
    float
    double
    long double

    Example: if out of two operands first operand is char type and the second is unsigned int type then the first will be converted to unsigned int during operation and the final result will be an unsigned int.

  2.  Explicit type conversion : It is also known as type casting. This is done by the programmer.Example: int x = 7, y = 3; float ans; ans = (float) x/y;
    in this example the result is converted to float data type by the user.

C Programming Tutorial in Odia Download Link

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here