ProgrammingHardProduct company OA
What is printed?
What is printed?
#define X 3
#define Y X * 2
#if Y == 6
#define Z 1
#else
#define Z 2
#endif
printf("%d %d", Z, Y + 1 * 2);- A. 1 7
- B. 1 14
- C. 2 8
- D. 1 8
Correct answer: D. 1 8
In #if, macros expand too: Y becomes 3 * 2 = 6, so Z is 1. In the printf, Y + 1 * 2 becomes 3 * 2 + 1 * 2 = 8. '14' treats Y as a parenthesised 6 and then multiplies (6 + 1) * 2.
More C Programming questions
- What is printed? c #define SHOW(x) printf(#x " = %d", x) int a = 3; SHOW(a 2 + 1);
- file1.c contains static int count = 5; at file scope. file2.c contains extern int count; and uses count in main. Nothing else defines…
- What is printed? c int a[] = {10, 20, 30, 40, 50}; int p = (int )(&a + 1); int q = &a[1] + 1; printf("%d %d %td", (p - 1), (q - 1), p - q);
- What is printed? c int a = 0, b = 1, c = 2; if (a++ || b-- && ++c) c += 10; printf("%d %d %d", a, b, c);
- What is the output? c int i = 0, s = 0; do { i++; if (i % 2) continue; s += i; } while (i < 7); printf("%d %d", i, s);
- What is printed? c char label(int n) { static char buf[8]; buf[0] = 'A' + n; buf[1] = '0'; return buf; } int main(void) { char a =…