What are these called [duplicate]

2020-04-03 04:20发布

Possible Duplicate:
What does ‘?’ do in C++?

What are these kind of statements in c++ called:

testNumber > 1 ? true : false;

9条回答
Viruses.
2楼-- · 2020-04-03 04:46

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.

查看更多
Animai°情兽
3楼-- · 2020-04-03 04:52

That's the conditional operator.

The expression a ? b : c evaluates to b if a is true and c if a is false.

In most languages, this is the only example of a ternary operator, an operator that takes three arguments.

查看更多
对你真心纯属浪费
4楼-- · 2020-04-03 04:53

It means

//If this is true,
testNumber > 1
//testNumber is bigger than 1, then
true
//it is a true statemant, or
false
//else statement is faulse

or you can see it like this:

if(testNumber > 1) {
true
}
else {
false
}
查看更多
登录 后发表回答