6.8 Comma Operator

When two or more expressions are separated by the comma operator, they evaluate from left to right. The result has the type and value of the rightmost expression (although side effects of the other expressions, if any, do take place). The result is not an lvalue. In the following example, the value 1 is assigned to R , and the value 2 is assigned to T :

R = T = 1,   T += 2,   T -= 1;

Side effects for each expression are completed before the next expression is evaluated.

A comma expression must be enclosed with parentheses if it appears where commas have some other meaning, as in argument and initializing lists. Consider the following expression:

f(a, (t=3,t+2), c)

This example calls the function f with the arguments a , 5 , and c . In addition, variable t is assigned the value 3 .


Previous Page | Next Page | Table of Contents | Index