Discussion
Point out the error, if any in the program.
#include <stdio.h>
int main()
{
int a = 10, b;
a >=5 ? b=100: b=200;
printf("%d\n", b);
return 0;
}
Answer: C
Correct answer: Error: L value required for b
Assignment binds more loosely than the conditional operator, so the line parses as
(a >= 5 ? b = 100 : b) = 200;
and the left-hand side is now a conditional expression, which is a value rather than an object - so it cannot be assigned to. Written as b = a >= 5 ? 100 : 200; it would compile and give 100.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development