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.
Pankaj said:
1 month 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)
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)
Sivarenjini said:
6 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)
Daniel said:
7 years ago
; is missing in the C option.
(1)
Reddy said:
7 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)
Mona said:
8 years ago
Option C is also not correct because there is no semi colon in the end of the statement.
(2)
Hemant said:
8 years ago
If they are being so specific about parenthesis. They should also include a semicolon in the end of their result mentioned. Because I believe the first option will also work.
Deepa said:
8 years ago
I did not understand the meaning of the operator ":" between the variables.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers