You have define the same abc
macro twice. Your compiler could have warned you like
warning: “abc” redefined #define abc “rd”
And you simply ignored the warning, which you shouldn’t, learn from warning. For good code practise define the macros under one tag, use #ifdef
, #endif
and #undef
. for e.g
#ifdef first
#define abc 10
#endif
And the define second macro similarly.
Macros got replaced at preprocessor
stage and it will consider last definition of abc
.
Finally your code look like
int main() { printf("%d","rd"); return 0; }
Now %d
expects argument of int
type but you have provided of "Rd"
i.e char*
type. So it prints some garbage
value.
How can memory be allocated to a macro? No memory is allocated for macros at runtime at all & these are just a textual replacement.
solved How can memory be allocated to a macro? [closed]