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
Join The Discussion
Comments ( 4 )
Related Questions on C Preprocessor
What is the purpose of the C preprocessor in C programming?
A. Compile C code
B. Optimize code
C. Preprocess code before compilation
D. Execute code
A. #define
B. #include
C. #ifdef
D. #pragma
What is the purpose of the #define directive in C preprocessing?
A. To include a header file
B. To define a macro
C. To declare a constant
D. To declare a variable
In C, which directive is used to conditionally include code based on preprocessor macros?
A. #ifdef
B. #ifndef
C. #if
D. #else
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