+ 11
What is this?
int x=2,y=1,z=2; int c=(y,x,z); cout<<c; There was a challenge q that looked like that. What is (y,x,z)? Never seen that before.
2 Antworten
+ 7
That's the comma operator. When you see "(x, y, z)", it evaluates to the last item in the list. It's useful if you need to evaluate a statement before checking a condition, like "(statement, condition)".
Don't forget about operator precedence, though! The parentheses are important here. If it was "c=x,y,z", c would then be equal to x rather than z, because assignment has higher precedence than the comma operator.
+ 8
Cool thanks.