How these macros are evaluated?
# define i 20
void fun();
int main(){
printf(\"%d\",i);
fun();
printf(\"%d\",i);
return 0;
}
void fun(){
#undef
There's no scope involved at all. Macros are handled at the preprocessing stage separately and independently from the compilation stage and have no concept of a C scope. Your examples could just as easily be:
#define i 20
void fun();
int main()
{
printf("%d",i);
fun();
printf("%d",i);
return 0;
}
void fun()
{
}
#undef i
#define i 30
And:
#define i 20
#undef i
#define i 30
void fun()
{
}
int main()
{
printf("%d",i);
fun();
printf("%d",i);
return 0;
}
You can see from those why it behaves the way it does.