user12769661
user12769661

Reputation:

Why is this output?

Here is the Code of:

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

Output is:%s Geeks For Geeks Geeks For Geeks

How is this output generated?

Upvotes: 0

Views: 1352

Answers (1)

kiran Biradar
kiran Biradar

Reputation: 12732

your printf will become

printf(scanf, scanf);

         |
         |
        \ /

printf("%s Geeks For Geeks ", "%s Geeks For Geeks" ); 

         |
         |       //%s is replaced with "%s Geeks For Geeks" string
        \ /

printf("%s Geeks For Geeks Geeks For Geeks ");

and on the console

%s Geeks For Geeks Geeks For Geeks

Aside: Please don't do this kind of coding. It sucks.

Upvotes: 5

Related Questions