C Programming - Expressions - Discussion

Discussion Forum : Expressions - General Questions (Q.No. 3)
3.
Which of the following is the correct usage of conditional operators used in C?
a>b ? c=30 : c=40;
a>b ? c=30;
max = a>b ? a>c?a:c:b>c?b:c
return (a>b)?(a:b)
Answer: Option
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.

Discussion:
30 comments Page 3 of 3.

Krishna said:   9 years ago
I have excuted the first option it is correct only.

Prit said:   9 years ago
I think both the option A and option C are true.
(1)

Prit said:   9 years ago
I can't understand.

Why not to choose option A?

Apoorva said:   9 years ago
I think, both the option A and C are correct.

Vibhor said:   10 years ago
Please post any example using this statement.

Anshul Jain said:   10 years ago
Any one explain me. Why option A is wrong?

Azhar said:   1 decade ago
It is not terminated with ";" (option C).

Laya said:   5 years ago
Can you explain clearly about this?
(1)

Souravb said:   2 decades ago
I cant understand it. Please help.

Daniel said:   8 years ago
; is missing in the C option.
(1)


Post your comments here:

Your comments will be displayed after verification.