[go: up one dir, main page]

0% found this document useful (0 votes)
19 views12 pages

C++ Ternary Operator Guide

The ternary operator allows replacing if-else statements in C++ by evaluating a condition and executing one of two expressions depending on if the condition is true or false, with the syntax condition ? expression1 : expression2.

Uploaded by

gabernora51
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views12 pages

C++ Ternary Operator Guide

The ternary operator allows replacing if-else statements in C++ by evaluating a condition and executing one of two expressions depending on if the condition is true or false, with the syntax condition ? expression1 : expression2.

Uploaded by

gabernora51
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Ternary Operator:-

In C++, the ternary operator (also known as the conditional


operator) can be used to replace if – else in certain
scenarios.
A ternary operator evaluates the test condition and executes
a block of code based on the result of the condition.
Its syntax is
condition ? expression1 : expression2;
Here, condition is evaluated and
• if condition is true, expression1 is executed.
• And, if condition is false, expression2 is executed.
The ternary operator takes 3
operands (condition, expression1 and expression2). Hence,
the name ternary operator.

Example : C++ Ternary Operator

You might also like