ProgrammingHardHCL · Tech Mahindra pattern
What is printed?
What is printed?
#define PR(x) printf(#x " = %d\n", x)
int main() {
int value = 42;
PR(value);
}- A. value = value
- B. value = 42
- C. Compilation error: #x is not valid syntax
- D. 42 = 42
Correct answer: B. value = 42
The # operator (stringizing) converts the macro argument's literal TEXT into a string literal, so #x becomes "value" (the identifier's spelling, not its runtime value). The expansion is printf("value" " = %d\n", value), and adjacent string literals concatenate: "value = %d\n" with value substituted as 42.
More C Programming questions
- What is printed? c #define CONCAT(a, b) a##b int main() { int xy = 100; printf("%d", CONCAT(x, y)); }
- What is printed? c #define ISEVEN(n) ((n) % 2 == 0) int main() { int x = 7; if (!ISEVEN(x)) printf("odd"); else printf("even"); }
- Assume 32-bit int. What is printed? c int flags = 0; flags |= (1 << 2); flags |= (1 << 4); flags &= ~(1 << 2); printf("%d", flags);
- What is printed? c #if defined(DEBUG) && !defined(RELEASE) #define LOG(x) printf("[debug] %sn", x) #else #define LOG(x) #endif int main()…
- What is printed? c int a = 10; int b = (a > 5) ? (a < 20 ? 1 : 2) : 3; printf("%d", b);
- What is printed? c #define N 5 #undef N #define N 10 int main() { printf("%d", N); }