question about function call

Feb 29, 2012 at 6:03am
I was taking a quiz on Cprogramming website, one question was:

What does the following code do:
int foo (int x, int y)
{
cout << x << y ;
}
int c=0;
foo( c++, c );

a. Undefined
b. 01
c. 00

The correct answer was a, but I test it on vs2010, the answer was b. I am confused now. Anyone could explain this? Thanks!
Feb 29, 2012 at 6:18am
Undefined means that it could be both b or c, depending on the compiler and whatever it cares about. If you compile the code you'll get a warning at most. It's even possible that most compilers would generate 01 here. However the standard says that it's undefined so you must never rely on the order of evaluation.
Feb 29, 2012 at 6:23am
I see. Thanks for your detailed explanation, hamsterman!
Topic archived. No new replies allowed.