How below macro is working in c programming language?

62 Views Asked by At

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.

1

There are 1 best solutions below

13
Andy A. On BEST ANSWER

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