Urgenthomework logo
UrgentHomeWork
Live chat

Loading..

Syntax:

Expression 1 ? Expression 2 : Expression 3

Meaning:

If the Expression 1 is true then the value returned will be given by Expression 2 otherwise it will be given by Expression 3

Example of Else – If:

Conditional Operator Homework Help

Example of Conditional Operator:

To find the maximum of a and b:{" "}

#include <stdio.h>
#include <conio.h>
int main()
{
int a,b,max;
printf(“Enter a and b: ”);
scanf(“%d %d”,&a,&b);

max = (a>b) ? a : b;
printf(“Maximum is %d”,max);

return;
}

Here the statement,

max = (a>b) ? a : b;
means,
if (a>b)
max = a;
else
max = b;

Topics in C Programming

Copyright © 2009-2023 UrgentHomework.com, All right reserved.