x>10 ? y=10 : y=20

I am studying past test for my final and one of the questions asks what the output of the following code is. I'm not sure what the expression with the "?" is, and I don't remember what it is called so I can't look it up. Does anybody know what this operation is called, or could somebody explain what is happening?

1
2
3
4
int x = 10;
int y = 0;
x>10 ? y=10 : y=20;
cout << y << endl;


The solution says the answer is 20, but i'm not sure how
Last edited on
See Conditional ternary operator
http://www.cplusplus.com/doc/tutorial/operators/

In effect, it's a concise if/else statement.
Topic archived. No new replies allowed.