ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
#define TWICE(x) x + x
printf("%d", 2 * TWICE(3));- A. 12
- B. 9
- C. 18
- D. 6
Correct answer: B. 9
TWICE(3) expands purely textually to 3 + 3. The full expression becomes 2 * 3 + 3, and by normal precedence (* before +) that is (2*3) + 3 = 6 + 3 = 9, not 2*(3+3)=12 as the macro name might suggest.
More C Programming questions
- What is printed? c #define LOG(msg) printf("[LOG] %sn", msg) #ifdef DEBUG #define TRACE(msg) LOG(msg) #else #define TRACE(msg) #endif int…
- What is printed? c #define CONCAT(a, b) a##b int xy = 42; printf("%d", CONCAT(x, y));
- 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"); }