B
Bo Sun
hi,
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:
second = first + 1;
first = 2;
third = second + 1;
therefore, result is unpredictable.
Which one is correct?
Many thanks...
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:
second = first + 1;
first = 2;
third = second + 1;
therefore, result is unpredictable.
Which one is correct?
Many thanks...