Expressions - General Questions :: Discussion


3.Which of the following is the correct usage of conditional operators used in C?
A.a>b ? c=30 : c=40;
B.a>b ? c=30;
C.max = a>b ? a>c?a:c:b>c?b:c
D.return (a>b)?(a:b)
Answer:  Option  C
Explanation:

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.

Tutorial Link:
Published by:Michael Daani

Comments are not available

Post your comments here:

Optional

Date to Date Current Affairs 2022

PakMCQs.net

Quick Links

GAT Subject



   Computer Science    English Mcqs    Agriculture    

Engineering



   Computer Science    Civil Engineering    

Technical



   Networking    Electronics    Database    

Past Papers



   Model Papers    FPSC Papers