Q: How do I turn on line numbers in the .Net C++ editor?
A: Under the Tools menu:
Q: I have the following code:
int i = 0; cout << ++i << ' ' << i << endl;
I expected the output to be
but intead it was
A: There is actually no way of telling which output you should see.
C++ does not guarantee what the "order of evaluation" will be of terms in an expression. A C++ compiler is free to evaluate the second use of i first and only then go and evaluate ++i. That would result in the output that you saw. A different C++ compiler might do it the way you expected. The lesson is that you should not depend on the order in which things get evaluated. Instead write the above code as:
int i = 0; cout << ++i << ' '; cout << i << endl;
Maintained by John Sterling (email@example.com). Last updated January 23, 2011