Conditional Expression in C 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:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!