Expressions

Q1: Which of the following is the correct usage of conditional operators used in C?

A a>b ? c=30;

B a>b ? c=30 : c=40;

C return (a>b)?(a:b)

D max = a>b ? a>c?a:c:b>c?b:c

ANS:C - max = a>b ? a>c?a:c:b>c?b:c

Option A: assignment statements are always return in paranthesis in the case of conditional operator. It should be a>b? (c=30):(c=40); Option B: it is syntatically wrong. Option D: syntatically wrong, it should be return(a>b ? a:b); Option C: it uses nested conditional operator, this is logic for finding greatest number out of three numbers.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.