After reading both of the following...
What does the comma operator , do?
How does the Comma Operator work
I am still not sure that I can't parse the following statement that I found in someone else's source code:
int i, n, val, locala = a, bestval = -INFINITY;
The comma operator is evaluated in left-to-right ordering, yes? If we use parentheses to show order of precedence, I think we have something like this:
(int i, (n, (val, (locala = a, (bestval = -INFINITY)))));
So, maybe, the original is equivalent to the following?
int bestval = -INFINITY;
int locala = a;
int val;
int n;
int i;
If so, why is the int
keyword applied to all of the variables instead of only the leftmost variable i
?
Also, the right-most expressions return their value, yes? So, locala = a
might return the value of locala
after the assignment is takes place. Does that mean that the variables i
, n
, and val
all get initialized? If so, what do they get initialized to? -INFINITY
? the value of a
?