-1

Code:

#include <stdio.h>
#define puts "%s C preprocessor"
int main()
{
    printf(puts, puts);
    return 0;
}

Output:

%s C preprocessor C preprocessor

See also...

Can anyone explain me the logic behind this output?

I tried to solve it,but I didn't get the proper explanation through my friends. If anyone can explain me ,it'll be very helpful.

Andy A.
  • 1,392
  • 5
  • 15
  • 28
  • 2
    Post code as text here instead of an external link of an image. Tell us what you have done so far to solve your problem. Macros are covered in any textbook on c. Don't shout (use all upper case). – Allan Wind Nov 27 '22 at 09:06
  • What is your closest explanation you can come up with? What did you find out how the macro is replaced by preprocessor? Which part is missing then to get the output? – Gerhardh Nov 27 '22 at 09:17
  • @AllanWind you don't shout – sakshi monst Nov 29 '22 at 08:14
  • @Gerhardh , no part is missing. closest explanation would be % s is taking next argument as a string – sakshi monst Nov 29 '22 at 08:17
  • 2
    Welcome to Stack Overflow! Please [edit] your post to add code and data as text ([using code formatting](https://stackoverflow.com/editing-help#code)), not images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and [many more reasons](https://meta.stackoverflow.com/a/285557). Images should only be used, in addition to text in code format, if having the image adds something significant that is not conveyed by just the text code/error/data. See [mcve] on what code is required. – Adriaan Nov 29 '22 at 08:47

1 Answers1

0

The macro let to (code after linker):

int main
{
    printf("%s C preprocessor", "%s C preprocessor");
    return 0;
}

printf works like:

enter image description here

The output is then

%s C preprocessor C preprocessor
Andy A.
  • 1,392
  • 5
  • 15
  • 28