Possible Duplicate:
What does ‘?’ do in C++?
What are these kind of statements in c++ called:
testNumber > 1 ? true : false;
Possible Duplicate:
What does ‘?’ do in C++?
What are these kind of statements in c++ called:
testNumber > 1 ? true : false;
Ternary operator.
Your expression is for finding whether the value is true or false. For example,
boolean c = testNumber > 1 ? true : false;
Here based on the value of testNumber, c will be true or false.
That's the conditional operator.
The expression
a ? b : c
evaluates tob
ifa
is true andc
ifa
isfalse
.In most languages, this is the only example of a ternary operator, an operator that takes three arguments.
It means
or you can see it like this: