ProgrammingHardWipro · Cognizant pattern
What is printed?
What is printed?
#define PRINT(x) printf(#x " = %d\n", x)
int main(void) {
int value = 42;
PRINT(value);
}- A. 42 = 42
- B. "value" = 42
- C. Compilation error
- D. value = 42
Correct answer: D. value = 42
The # operator stringizes the macro argument as written in source, turning x into the literal string "value" (not its runtime value), so the expansion is printf("value" " = %d\n", value); adjacent string literals concatenate, producing "value = %d\n" with value substituted as 42.
More C Programming questions
- What is printed? c #define MIN(a, b) ((a) < (b) ? (a) : (b)) int calls = 0; int next(void) { calls++; return calls; } int main(void) { int…
- What is printed? c #if defined(DEBUG) const int mode = 1; #else const int mode = 0; #endif int main(void) { printf("%d", mode); }
- What is printed? c #define ISODD(x) (x % 2 == 1) int main(void) { printf("%d", ISODD(4 - 1)); }
- What is printed? c #define STR(x) #x #define XSTR(x) STR(x) #define VERSION 7 int main(void) { printf("%s %s", STR(VERSION)…
- What is printed? c #define SWAP(a, b) do { int t = a; a = b; b = t; } while (0) int main(void) { int x = 1, y = 2; if (x < y) SWAP(x, y)…
- What is printed? c #define A 1 #define B (A + 1) #undef A #define A 10 int main(void) { printf("%d", B); }