Implicit conversions
Implicit conversions
When an expression is used in the context where a value of a different type is expected, conversion may occur:
int n = 1L; // expression 1L has type long, int is expected n = 2.1; // expression 2.1 has type double, int is expected char *p = malloc(10); // expression malloc(10) has type void*, char* is expected
Conversions take place in the following situations:
Conversion as if by assignment
- In the assignment operator, the value of the right-hand operand is converted to the unqualified type of the left-hand operand.
- In scalar initialization, the value of the initializer expression is conver