What's happening here?
#include <iostream>
using namespace std;
int main(){
int x=0,y=0;
true? ++x, ++y : --x, --y;
cout << "x: " << x << endl;
cout << "y: " << y << endl; //why does y=0 here?
x=0,y=0;
false ? ++x, ++y : --x, --y;
cout << "x: " << x << endl;
cout << "y: " << y << endl;
}
x: 1
y: 0
x: -1
y: -1
The second case seems fine. I would expect both x and y to increment to 1 in the first case but only the left hand operand increments.
#include <iostream>
andusing std::cout; using std::endl;
cout
,#include <iostream>
andusing namespace std;
are just noise. If that's all that is missing, and the reader can't figure out how to get it to compile, s/he has no business answering C++ questions.