ProgrammingHardWipro · Cognizant pattern
What is printed?
What is printed?
#define CONCAT(a, b) a##b
int xy = 42;
printf("%d", CONCAT(x, y));- A. 42
- B. Compile-time error: a##b is invalid syntax
- C. 0
- D. x times y, computed at compile time
Correct answer: A. 42
## is the token-pasting operator: CONCAT(x, y) literally glues the tokens x and y together into the single identifier xy at preprocessing time, which then refers to the existing variable xy, printing 42.
More C Programming questions
- What is printed? c #if defined(STDC) && STDCVERSION >= 199901L int x = 10; #else int x = 20; #endif printf("%d", x);
- What is printed? c #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define CLAMP(x, lo, hi) MIN(MAX(x, lo), hi) #define MAX(a, b) ((a) > (b) ?…
- What is printed? c #define INCR(x) (++x) int arr[3] = {10, 20, 30}; int i = 0; printf("%d", arr[INCR(i)]);
- What is printed? c #define ISEVEN(n) (((n) % 2) == 0) int main(void) { int x = 7; if (ISEVEN(x)) printf("even"); else printf("odd"); }
- What happens when this runs? c int x; printf("%d", x);
- What happens when this runs? c char p; { char buf[20] = "hello"; p = buf; } printf("%s", p);