Machine-translated by Google. Questions are authored in English.
Top

Discussion

# include <stdio.h>
# define scanf  "%s Geeks Quiz "
int main()
{
   printf(scanf, scanf);
   return 0;
}

 

  • A.Compiler Error
  • B.%s Geeks Quiz
  • C.Geeks Quiz
  • D.%s Geeks Quiz Geeks Quiz

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.