Discussion :: C Preprocessor
-
What will be the output of the program?
#include
A.
Error: in macro substitution |
B.
Error: invalid reference 'x' in macro |
C.
print 'multiply' |
D.
No output |
Answer : Option C
Explanation :
The macro #define str(x) #x replaces the symbol 'str(x)' with 'x'.
The macro #define Xstr(x) str(x) replaces the symbol 'Xstr(x)' with 'str(x)'.
The macro #define oper multiply replaces the symbol 'oper' with 'multiply'.
Step 1: char *opername = Xstr(oper); The varible *opername is declared as an pointer to a character type.
=> Xstr(oper); becomes,
=> Xstr(multiply);
=> str(multiply)
=> char *opername = multiply
Step 2: printf("%s\n", opername); It prints the value of variable opername.
Hence the output of the program is "multiply"
Be The First To Comment