Conditional Operator/ Special Operator is ternary in nature i.e. it require three operands to perform an operation.It is denoted by " ? : "
The execution of conditional operator is as follow-:
(a-) The first operand is converted to "bool" and then it is evaluated.
(b-) If the first operands evaluate to TRUE[1], the first expression will execute.
(c-) If the first operands evaluate to FALSE[0], then second expression will execute.
Syntax-:
condition?expression 1 : expression 2;
Example-:
int x,y;
printf("enter value of y");
scanf("%d",y);
x=(y>5?3:4);
If the value input by user is greater than 5,then output will be 3 and if the value inputted is less than 5, then output will be 4.
please follow techprogramiz...
ReplyDeleteSuch a knowledgeable blog
ReplyDeletethanks for feedback
Delete