Possible Duplicate:
why does 3,758,096,384 << 1 gives 768
Today I found out that following code compiles with gcc:
#include <iostream>
int main()
{
int x = (23,34);
std::cout << x << std::endl; // prints 34
return 0;
}
Why does this compiles? What is the meaning of (…, …)?
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 is34which is why your code outputs34.I would also like to mention that
,is not an operator in a function call:Here
,acts a separator of arguments. It doesn’t act as operator. So you pass two arguments to the function.However,
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:Hope that helps. 🙂