cmacrospreprocessorformat-specifiersusing-directives

How below macro is working in c programming language?


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.


Solution

  • 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