Thursday 16 January 2014

Explain conditional operator with example.

Conditional operator
Here if given condition is true then exp1 is evaluated else exp2.

syntax
condition?(exp1) : (exp2);

Write a program to show conditional operator
#include<stdio.h>
#include<conio.h>
main
int x=2;
()
{
clrscr();
printf("Result=%d",1==2?4:5);
}

output
Result=5

No comments:

Post a Comment