Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

? c++

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"
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
3+1 =