Home C Language Basic C Programs Ternary Operator

Ternary Operator

Write a C Program to demonstrate Ternary operator or Conditional operator.

Ternary operator is used for decision making in place of longer if and else conditional statements.

The ternary operator take three arguments:

  • The first is a comparison argument
  • The second is the result upon a true comparison
  • The third is the result upon a false comparison


int main()
   int a ,b;
   printf(“Enter two numbers : \n”);
   scanf(“%d %d”,&a,&b);
   a>b?printf(“%d is BIG \n”,a) : printf(“%d is BIG\n”,b);
   return 0;

Output :
Enter two numbers :
618 811
811 is BIG

For improvement of your coding skills we give some tasks along this. If you solve this tasks and send to our email (onlineexamshubteam@gmail.com) with your details. We will display your details(like Name, City, college, photo) in our site.

 Task: Write a c program to check given number is even or odd using Ternary operator.