Discussion
What will be the output of the following C code?
#include <stdio.h>
#define hello 10
main()
{
#ifdef hello
#undef hello
#define hello 100
#else
#define hello 200
#endif
printf("%d",hello);
}
Answer: C
Correct answer: 100
hello is defined, so the #ifdef branch runs: the old definition is removed with #undef and a new one, 100, put in its place. Using #undef before redefining is exactly the right way to do this, since it avoids the redefinition warning. The output is 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