Programming Languages C Objective
Mar 08, 2013

What will be the output of the following statements ?

int a=5,b=6,c=9,d;     d=(a<b?(a>c?1:2):(c>b?6:8)); printf("%d",d);

Choose the correct answer:
A) 1
B) 2
C) 6
D) 8
Detailed Explanation

(a<b) is false so is (a>c), hence '2' gets printed out.
Notes :
The conditional ? and : are called ternary operators as they take three arguments.

In General:
expression A ? expression B : expression C
If expression A is true, then the value returned will be expression B, otherwise expression C will get returned.

Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback