In C++, ,
is an operator, and therefore (23,34)
is an expression just like (23+34)
is an expression. In the former, ,
is an operator, while in the latter, +
is an operator.
So the expression (23,34)
evaluates to the rightmost operand which is 34
which is why your code outputs 34
.
I would also like to mention that ,
is not an operator in a function call:
int m = max(a,b);
Here ,
acts a separator of arguments. It doesn't act as operator. So you pass two arguments to the function.
However,
int m = max((a,b), c);
Here first ,
is an operator, and second ,
is a separator. So you still pass two arguments to the function, not three, and it is equivalent to this:
int m = max(b, c); //as (a,b) evaluates to b
Hope that helps. :-)