ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
#define STR(x) #x
#define CAT(a, b) a##b
int xy = 7;
printf("%s %d", STR(x+y), CAT(x, y));- A. x+y xy
- B. Compilation error
- C. x+y 7
- D. 7 7
Correct answer: C. x+y 7
# turns the macro argument into a string literal, so STR(x+y) is "x+y". ## pastes tokens, so CAT(x, y) becomes the identifier xy, whose value is 7. No variables x or y are needed.
More C Programming questions
- What is printed? c int x = 2; switch (x) { case 1: printf("A"); case 2: printf("B"); case 3: printf("C"); break; default: printf("D"); }
- What is printed? c int n = 5; while (n-- > 2) printf("%d", n); printf(" %d", n);
- Given int x = 1, y = 2; const int p = &x; int const q = &x; which pair of statements both fail to compile?
- What is printed? c enum { A, B = 5, C, D = 2, E }; printf("%d %d %d", A, C, E);
- With 4-byte int, what is printed? c int a[] = {1, 2, 3}; char p = (char )a; p += 4; printf("%d", (int )p);
- What is printed? c int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; printf("%d %d", ((a + 1) + 2), a + 1);