Discussion
#include <stdio.h>
#define square(x) x*x
int main()
{
int x;
x = 36/square(6);
printf("%d", x);
return 0;
}
Answer: B
Correct answer: 36
The macro has no parentheses, so square(6) expands to the bare text 6*6 and the statement becomes
x = 36/6*6;
/ and * have equal precedence and associate left to right, so this is \((36/6) \times 6 = 6 \times 6 = 36\), not 1. Writing the macro as #define square(x) ((x)*(x)) is what prevents this.
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