Question discussion

What is the output of the following C program?#include #define STR(x) #x #define CAT(a, b) a##b int main() { int xy = 7; printf("%s %d", ST…

2182Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
#define STR(x) #x
#define CAT(a, b) a##b
int main() {
    int xy = 7;
    printf("%s %d", STR(a+b), CAT(x, y));
    return 0;
}
  • Ax+y 7
  • Ba+b 7
  • Ca+b xy
  • DSTR(a+b) 7
Correct answer: B

Explanation

The # operator turns the argument into the string "a+b" and ## pastes x and y into the identifier xy, whose value is 7.

Discussion 0

Nobody has replied yet. Start the discussion!