>Am i right
Barring sneaky tricks, you're right. But anything is possible if you're desparate enough to come up with a workaround that might work. For example:
#include <stdio.h>
void change()
{
#define printf(fmt,x) printf ( "%d\n", 5 )
}
int main()
{
int i=5;
change();
i=10;
printf("%d\n",i);
return 0;
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>but what is fmt in # define
fmt and x replace "%d\n" and i in the printf call from main. Because they're not terribly important, the macro ignores them and uses its own complete call to printf. Since you know that the format string is what you want, you could also have done this:
#define printf(fmt,x) printf ( fmt, 5 )
Or even this if x is sure to be 10:
#define printf(fmt,x) printf ( fmt, x - 5 )
But it's generally a bad idea to redefine standard names, which is why this (and any other solution I can think of right now) is a sneaky hack.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401