Discussion
What will be the output of the program?
#include <stdio.h>
#define MAX(a, b) (a > b ? a : b)
int main()
{
int x;
x = MAX(3+2, 2+7);
printf("%d\n", x);
return 0;
}
Answer: B
Correct answer: 9
The macro body parenthesises nothing, so the expansion is (3+2 > 2+7 ? 3+2 : 2+7). Addition binds tighter than >, so the comparison is \(5 > 9\), which is false, and the result is \(2+7 = 9\). Here the missing parentheses happen not to matter, but with an argument such as 1&2 they would.
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