No-promotion arithmetic types conversions

No-promotion conversions between arithmetic types may not always be able to represent the same value exactly:
  • negative integer to an unsigned type, the resulting value corresponds to its 2's complement bitwise representation (i.e., -1 becomes the largest value representable by the type, -2 the second largest, ...).
  • conv. from/to bool consider false equivalent to zero (for numeric types) and to null pointer (for pointer types); true is equivalent to all other values and is converted to the equivalent of 1.
  • floating-point type to an integer type, the value is truncated (the decimal part is removed). If the result lies outside the range of representable values by the type, the conversion causes undefined behavior.
  • if the conv. is between numeric types of the same kind, the conversion is valid, but the value is implementation-specific (may not be portable).
Read more
data-type-conversion types implicit-conversion promotion

Follow Quizful

Send Feedback