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?
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 1 of 3.
Sivarenjini said:
7 years ago
C option is also wrong.
There must be semicolon at the end. Then only it can be considered as valid.
There must be semicolon at the end. Then only it can be considered as valid.
(3)
Husain said:
5 years ago
A is not the correct answer. It will always generate the error of lvalue required
instead righteous way to write statement A is;
c=a>b?30:40;
Of course, C, the option can also be termed wrong in syntax for not terminating it with a semicolon.
instead righteous way to write statement A is;
c=a>b?30:40;
Of course, C, the option can also be termed wrong in syntax for not terminating it with a semicolon.
(2)
Heena said:
1 decade ago
max = a>b ? (a>C ? a : c) : (b>c ? b :c);
Now I guess this statement is more clear.
Now I guess this statement is more clear.
(2)
Mona said:
8 years ago
Option C is also not correct because there is no semi colon in the end of the statement.
(2)
Pankaj said:
5 months ago
Option C does not end with a semicolon. So option A is correct.
(1)
Laya said:
5 years ago
Can you explain clearly about this?
(1)
Daniel said:
8 years ago
; is missing in the C option.
(1)
Reddy said:
8 years ago
C. Also a syntax error because at the semicolon has missed.
(1)
Sankar said:
8 years ago
Here the expression is evaluated from right to left.
(1)
Prit said:
9 years ago
I think both the option A and option C are true.
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers