Discussion
# include <stdio.h>
# define scanf "%s Geeks Quiz "
int main()
{
printf(scanf, scanf);
return 0;
}
Answer: D
Correct answer: %s Geeks Quiz Geeks Quiz
scanf is redefined as a string literal, so the call expands to
printf("%s Geeks Quiz ", "%s Geeks Quiz ");
The first copy is the format string and the second is the argument that its %s consumes. The %s is replaced by the whole second string, so the output is %s Geeks Quiz Geeks Quiz. Nothing stops a macro from shadowing a standard library name, which is exactly why it is a bad idea.
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