Comma Operator
phuc_tran,
While searching for something else, I stumbled across this tid-bit in an on-line book available from Microsoft MSDN called "C++ A Beginners Guide" by Herbert Schildt. It is something I would normally read right past without even noticing. However I remembered your question so I spent a little time looking at it. The following is copied directly from Chapter 7 page 31.
var = (count=19, incr=10, count+1);
"first assigns count the value 19, assigns incr the value 10, then adds 1 to count, and finally assigns var the value produced by the entire comma expression, which is 20."
I'm guessing the assignment of 20 to var is because this operation was the very last to be performed in the series of operations.
Ken
|