C Preprocessor

Q1: What will be the output of the program?
#include<stdio.h>
#define str(x) #x
#define Xstr(x) str(x)
#define oper multiply

int main()
{
    char *opername = Xstr(oper);
    printf('%s\n', opername);
    return 0;
}

A Error: invalid reference 'x' in macro

B Error: in macro substitution

C No output

D print 'multiply'

ANS:A - Error: in macro substitution

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'



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.