I am sure I am having a silly moment here, but I am trying to understand the comma operator in C++ and "operator precedence" rules (which I believe are a general maths thing, hence me posting this in the Maths TA too:)).

From what I have read about the comma operator, we have two facts

1) The result of it is the right hand value, so for example a,b would yield b.
2) It has the lowest operator precedence. I read this means "it's always the last one to bind to an expression", but I don't quite get that bit.

So, if we have

a = (b , c)

the evaulation sequence would first be (b,c) which would yield c, hence a would be assigned c. But I am struggling with

a = b , c

This is apparently equivalent to

(a = b) , c

The result of this expression is b.

Now, I know we have to evaluate the brackets first, which results in b, so we then have

b, c

Q1) From rule 1 above, why is the result hence not c? Clearly something is incorrect in what I deduced above, but I cannot see it...

Q2) Can someone clarify fact 2) above and what "it's always the last one to bind to an expression" means?

One maybe important fact: In C++ it's possible to override comma-operators which may lead to confusion since if it is overridden it starts acting like a function call which means there's no order defined in which left- and rightside expressions are executed. For this you can find a sample at i.e. http://madebyevan.com/obscure-cpp-features/

Yes, that's correct, but the c is never assigned to anything. You have two different statements, "a = b" and "c", so a is equal to b afterward, no matter in which order the statements are evaluated.

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

1. This is because the comma seperates the two statements, so the expression

a = b , cis equivalent to( a = b ) , cFor some further info about comma-operator you can start reading http://en.wikipedia.org/wiki/Comma_operator

One maybe important fact: In C++ it's possible to override comma-operators which may lead to confusion since if it is overridden it starts acting like a function call which means there's no order defined in which left- and rightside expressions are executed. For this you can find a sample at i.e. http://madebyevan.com/obscure-cpp-features/

Hope that helps,

ZOPPO