Bo Sun <b0*****@cs.tamu.edu> wrote in message news:<Pi******************************@unix.cs.tam u.edu>...

suppose I have the following expression (all variables are of integer

type)

result = (first = 2, second = first + 1, third = second + 1);

what is the value of result?

1) result is 4. because the expressions are evaluated from left to right;

2) result is unpredictable. Because the comma operator returns the value

of he last expression. for the presivous expressions, there is no

guarantee of theorder of evaluation. Therefore, we could evaluate in the

following order:

One thing to keep in mind is the difference between the comma operator and

the commas used to seperate function arguments.

The comma operator guarantees the order of evaluation (left or right).

But the commas that separate the function arguments have no such guarantee.

So, in your example, after your statement, first will equal 2, second will

equal three, and both third and result will equal 4.

But if you change that around to this:

void some_func(int, int, int);

some_func(first = 2, second = first + 1, third = second + 1);

In this case, the value of the second and third arguments to some_func() and

the values of second and third after the call to some_func() have no guaranteed

value.

samuel