Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explain C code snippet: preprocessor + printf =?

The output for this code snippet is %s is a string is a string. Please explain.

#include <stdio.h>

#define scanf "%s is a string"

int main()
{
    printf(scanf, scanf);  
}
like image 470
Vish Avatar asked Sep 14 '26 16:09

Vish


1 Answers

What exactly do you want us to explain? Subsititute the macro and get

printf("%s is a string", "%s is a string");

The rest is the expected normal everyday behavior of printf.

P.S. #define scanf ...???

like image 178
AnT Avatar answered Sep 17 '26 05:09

AnT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!