Categories
c programming tips and tricks

Use of Conditional Operator

The Conditional operator is also known as the Ternary operator. We mostly use it in the following form:

x = (y < 0) ? 10 : 20;

But in C++, you can also use it in the following manner:

(c < 0 ? a : b) = 1;

// If c < 0 then a = 1
// If c > 0 then b = 1

Leave a Reply

Your email address will not be published. Required fields are marked *