Type of Conditional C Expressions

In C, a conditional expression is not an lvalue, nor is its result.

Type of One Operand Type of Other Operand Type of Result
Arithmetic Arithmetic Arithmetic type after usual arithmetic conversions
Structure or union type Compatible structure or union type Structure or union type with all the qualifiers on both operands
void void void
Pointer to compatible type Pointer to compatible type Pointer to type with all the qualifiers specified for the type
Pointer to type NULL pointer (the constant 0) Pointer to type
Pointer to object or incomplete type Pointer to void Pointer to void with all the qualifiers specified for the type

C In GNU C, a conditional expression is a valid lvalue, provided that its type is not void and both of its branches are valid lvalues. The following conditional expression (a ? b : c) is legal under GNU C:

(a ? b : c) = 5
/*  Under GNU C, equivalent to (a ? b = 5 : (c = 5))  */

This extension is available when compiling in one of the extended language levels.

Related References

IBM Copyright 2003