ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
#define CONCAT(a, b) a##b
int main() {
int xy = 100;
printf("%d", CONCAT(x, y));
}- A. 100
- B. 0
- C. xy
- D. Compilation error: ## is only valid for numeric literals
Correct answer: A. 100
The ## operator pastes the two argument tokens together at the TEXT level before compilation, so CONCAT(x, y) becomes the single identifier xy — which happens to be the variable already declared with value 100.
More C Programming questions
- 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); }
- Assume a 64-bit LP64 ABI. What is printed? c int a = 10; int p = &a; int pp = &p; pp = 20; printf("%d %d %d", a, p, pp);