ProgrammingHardWipro · Cognizant pattern
What is printed?
What is printed?
#define TWICE(x) (2 * (x))
#define FOUR_TIMES(x) TWICE(TWICE(x))
printf("%d", FOUR_TIMES(3));- A. 12
- B. 9
- C. 6
- D. 24
Correct answer: A. 12
FOUR_TIMES(3) expands to TWICE(TWICE(3)), inner TWICE(3) becomes (2*(3))=6, then outer TWICE((2*(3))) becomes (2*((2*(3)))) = 2*6 = 12.
More C Programming questions
- What is printed? c #define ISEVEN(n) ((n) % 2 == 0) int a = 7; printf("%d", ISEVEN(a + 1));
- What is printed? c #define EMPTY #define SEMI ; int x = 5 EMPTY SEMI printf("%d", x);
- What is printed? c #define PRINT(x) printf(#x " = %dn", x) int main(void) { int value = 42; PRINT(value); }
- 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)); }