Turnary Operator or Conditional Operator - C Tutorial

Another form of if else (Turnary Operator)

We can also judge the condition using ternary operator. Ternary operator checks whether a given condition is true and then evaluates the expressions accordingly. It works as follows.

condition ? expression1 : expression2;

If the condition is true, then expression1 gets evaluated, otherwise expression2 gets evaluated.

#include 
int main()
{
    int age;
    printf("Enter age");
    scanf("%d", &age);
    (age >= 18) ? printf("eligible to vote\n") : printf("not eligible to vote\n");
    return 0;
}