What will be output after executing following code?
#include<stdio.h>
# define a 10
void main()
{
printf("%d..", a);
foo();
printf("%d", a);
}
void foo()
{
#undef a
#define a 50
}
#include<stdio.h>
# define a 10
void main()
{
printf("%d..", a);
foo();
printf("%d", a);
}
void foo()
{
#undef a
#define a 50
}A. 10..50
B. 10..10
C. 0
D. Error
Answer: Option B

what is the functionality of #undef...
lets discuss
it should be 10..50, why it is 10..10
Tej Deep coorect!
just like the previous sum
correct option is B
since the macro which is defined, is applicable for all the functions mentioned below. so up to the function invocation the macro a = 10
And in the function body, macro a becomes undefined. and again redefined in the function body as a = 50. whatever the changes we have made in the function body is only accessible in the the function. and these modification not applicable outside of that particular function. so macro a is not undefined.
Actually it should give error, no proper header file..So the correct answer must be D