by R4R Team

Conditional Expression in C programming Language is look like:

Syntax-

Condition?X:Y

-If condition is True then X will return otherwise Y return.

Example-
(1==1)?2:3 // return 2
(1==8)?2:3 // return 3


program-

#include< stdio.h>
int main()
{
int a=1;
int ans=(a==1)?2:3;
printf("%d",ans);
}


output-

2

-In this program, we have a integer variable i.e. a=1
-(a==1) will become True that's by it execute first part and return 2 that will store in 'ans' variable.
-Then we will print the 'ans' variable,output is 2.




Leave a Comment: