📜  ? c++代码示例

📅  最后修改于: 2022-03-11 14:44:45.761000             🧑  作者: Mango

代码示例1
The Conditional (or Ternary) Operator (?:)

(expression 1) ? expression 2 : expression 3

If expression 1 evaluates to true, then expression 2 is evaluated.

If expression 1 evaluates to false, then expression 3 is evaluated instead.
  
// ternary operator checks if
// marks is greater than 40
int marks = 50;
string result = (marks >= 40) ? "passed" : "failed";
// result = "passed"