Discussion
What will be the output of the following C code?
#include <stdio.h>
#define a 2
main()
{
int r;
#define a 5
r=a*2;
printf("%d",r);
}
Answer: A
Correct answer: 10
The preprocessor works on the text in order and ignores the braces entirely, so by the time it reaches r = a*2; the macro a has been redefined to 5. The statement becomes r = 5*2;, giving 10. Expect a redefinition warning, since there is no #undef in between.
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