coercion

Forced type conversion of C language self-learning

1 #include <stdio.h>
 2  
3  int main()
 4  {
 5      double num = 2.330 ; // No need + double quotes when assigning 
6      printf( " The integer part of num is %d\n " ,( int )( num));
 7      return  0 ;
 8 }

Coercion type conversion is achieved by defining the type conversion operation. The
    expression is: (data type) (expression)
    Note:
        1. Both the data type and the expression must be enclosed in parentheses, such as (int)(x/2+y) Written as (int)x/2+y is to convert x to int, then divide by 2 and add it to y.


        2. The type and variable value of the original data will not be changed after the conversion, and it is only temporarily converted in this operation.


        3. The operation result after forced conversion does not follow the rounding principle.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325062607&siteId=291194637