This Blog is protected by DMCA.com

Explain the conditional operator in C with the help of an example. Compare it with if...else statement.

THE CONDITIONAL OPERATOR IN C 

The conditional operator works on three operands, so it is also known as the ternary operator. It is represented by two symbols, i.e., '?' and ':'. 

If the first operand condition is true, the second operand represents the value entire conditional expression, if is false then the third operand represents the value.



The syntax is as follows:

(condition)? (expression1): (expression2);

If condition is true, expression1 is evaluated else expression2 is evaluated.


Let us see the following examples:

(i) x= (y<20) ? 9: 10;

This means, if (y<20), then x=9 else x=10;



Comments

College Admission

Best Career Option After Class 12 Course List

slider1

Blog E-commerce Auto Slider
Product 1
Product 4
Product 4
Product 4
Product 4
Product 4
Product 4

IIM Calcutta

 

IIM Calcutta

 

Apply For Admission


SUBSCRIBE

This Blog is protected by DMCA.com

Admission

SUBSCRIBE

OlderPost

Contact Form

Name

Email *

Message *

Share