Discussion
What will be the output of the program?
#include <stdio.h>
#define MAX(a, b, c) (a>b ? a>c ? a : c: b>c ? b : c)
int main()
{
int x;
x = MAX(3+2, 2+7, 3+7);
printf("%d\n", x);
return 0;
}
Answer: C
Correct answer: 10
The macro expands to a nested conditional. With \(a = 3+2 = 5\), \(b = 2+7 = 9\) and \(c = 3+7 = 10\):
(5>9 ? … : 9>10 ? 9 : 10)
The first test fails, so the else branch is taken; \(9 > 10\) also fails, leaving 10. Addition binds tighter than the comparisons, so the unparenthesised arguments happen to be safe here.
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