CKTIS / C
type conversion — concept C23
Conversions apply promotions and type changes; narrowing may lose value, out-of-range signed conversion is implementation-defined, and a pointer cast repairs neither alignment nor validity.
Version: C23
Syntax
type conversionConversions apply promotions and type changes; narrowing may lose value, out-of-range signed conversion is implementation-defined, and a pointer cast repairs neither alignment nor validity.
Before a narrowing conversion, compare the source range with INT_MIN/INT_MAX or the target type limits. Casting double to an integer discards the fractional part, but an out-of-range result is undefined; text parsing needs a function with end and error checks.
Promotions mean unsigned char + unsigned char usually computes in int, while usual conversions may turn a negative operand into an unsigned value. A pointer cast creates no target-type object, guarantees no alignment, and bypasses no aliasing rule.
Examples
#include <stdio.h>
int main(void) { double input = 7.9; int truncated = (int)input; printf("%d\n", truncated); return 0; }
Result
7
Conversions apply promotions and type changes; narrowing may lose value, out-of-range signed conversion is implementation-defined, and a pointer cast repairs neither alignment nor validity.