Sequenced expressions

suggest change

The following expressions are sequenced:

a && b
a || b
a , b
a ? b : c
for ( a ; b ; c ) { ... }

In all cases, the expression a is fully evaluated and all side effects are applied before either b or c are evaluated. In the fourth case, only one of b or c will be evaluated. In the last case, b is fully evaluated and all side effects are applied before c is evaluated.

In all cases, the evaluation of expression a is sequenced before the evaluations of b or c (alternately, the evaluations of b and c are sequenced after the evaluation of a).

Thus, expressions like

x++ && x++
x++ ? x++ : y++ 
(x = f()) && x != 0
for ( x = 0; x < 10; x++ ) { ... }
y = (x++, x++);

have well defined behavior.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents