C ++ data type coercion

The default automatic conversion rule converts
char type to int type.
When operators are used for different data types, they are automatically upgraded to the higher ranked types.
The expression is automatically converted to the type of the final variable.
Type coercion: static_cast <DataTType> (Value)
    DataType is the target data type to be converted, and Value is the variable or literal value to be converted.
C language style coercion conversion:
    booksPerMonth = (double) books / months;
pre-standard C ++ form: (use less, just know)
    booksPerMonth = double (books) / months; // put the data type before the operand, The parentheses are placed around the operand.

Published 31 original articles · Like1 · Visits1156

Guess you like

Origin blog.csdn.net/quietbxj/article/details/105506127