C-Conditional-Operator .

In this session i have discussed conditional operator in C .


Conditional-Operator :

Conditional Operator also known as ternary operator(?:) . It is look like below .

        expression1 ? expression2 :expression3    
    

It uses the three operands . The first operand is used to give the condition and if the condition is true then second operand will be evaluate other wise third operand will be evaluate .

Example : Write a program that will check the maximum value among two values .

    #includ<stdio.h> 
    int main()
    {          
            int x=35;
            int y=20;
            int max=(x>y)?x:y ;
            printf("MAX= %d",max);
            return 0;
    }
    
    OUTPUT : MAX=35
    


Welcome to AndroidATPoint.

back image                     next image