ternary operator   ?:

Syntax: condition ? first_statement : second_statement;

If condition is true then first_statement will be executed otherwise second_statement will be executed.

Example:

#include
int main()
{
    int n;
    printf("Enter a value : ");
    scanf("%d",&n);
    (n>0)? printf("Value is positive") : printf("Value is negative");
    return 0;
}

OUTPUT

Input a value : -10
Value is negative


Next Previous