{ A destination to learn coding }

Operators


The Ternary Operator (?)

Syntax:
(a operator b)? a:b;

Ternary operator is a kind of conditional operator.

For example,
(5>4)? x=100:x=200;
In the above example, if 5>4 is true, then x=100; else x=200.

In ternary operator there are 3 expressions in total. Exp1? Exp2:Exp3;
If Exp1 is true , Exp2 is evaluated. If Exp1 is false, Exp3 is evaluated.

int x=9,y;
(x==6)? printf("x and y are equal):printf("x and y arn't equal");
Output: x and y arn't equal		
			
int a=23,b; b=(a>20)? 1240:1333; printf("%d",b); Output: 1240
Code to check the bigger number using ternary operator.
#include<stdio.h>
int main()
{
  itn a, b, big;
  printf("Enter 2 integers\n");
  scanf("%d%d",&a,&b);

  big=(a>b)? a:b;
  printf("The bigger number is %d",big);

  return 0;
}
Try this
Code to find area and circumference of the cirlce
Conversion of temperature from celsius to fahrenheit
Conversion of temperature from fahrenheit to celsius
C Codes