ProgrammingVery hardProduct company OA
What is printed?
What is printed?
#define VAR(n) v##n
#define PRINT(n) printf("%d ", VAR(n))
int v1 = 10, v2 = 20, v12 = 30;
PRINT(1); PRINT(1 + 1); PRINT(12);- A. 10 11 30
- B. Compilation error
- C. 10 12 30
- D. 10 20 30
Correct answer: A. 10 11 30
## pastes only the adjacent tokens: VAR(1 + 1) becomes v1 + 1, which is 11, not v2. The preprocessor never evaluates 1 + 1. PRINT(12) pastes into the single identifier v12.
More C Programming questions
- Assume 32-bit unsigned int. What is printed? c unsigned int n = 5; int count = 0; for (unsigned int i = n; i < n + 3; i -= 2) count++…
- What is printed? c char w[][6] = {"red", "green", "blue"}; printf("%zu %zu %zu", sizeof(w), sizeof(w[1]), strlen(w[1]));
- What is printed? c int m = 0; long p(long b, int e) { if (e == 0) return 1; long h = p(b, e / 2); m++; if (e % 2) { m++; return h h b; }…
- What is printed? c enum Flag { RED = 1, GREEN = RED << 1, BLUE = GREEN << 1, ALL = RED | GREEN | BLUE }; printf("%d %d", ALL, ALL & ~GREEN);
- What is printed? c void rev(char s, int i, int j) { if (i >= j) return; char t = s[i]; s[i] = s[j]; s[j] = t; rev(s, i + 2, j - 2); } int…
- Why are multi-statement macros usually written as #define M(x) do { ... } while (0)?