ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
#define IS_EVEN(n) ((n) % 2 == 0)
int a = 7;
printf("%d", IS_EVEN(a + 1));- A. 1
- B. 0
- C. 8
- D. Compilation error
Correct answer: A. 1
Because the macro body fully parenthesizes its parameter, IS_EVEN(a+1) safely expands to ((a + 1) % 2 == 0) = (8 % 2 == 0) = (0 == 0) = 1 (true), with no precedence surprises since (a+1) stays grouped.
More C Programming questions
- 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)); }
- What is printed? c #define STR(x) #x #define XSTR(x) STR(x) #define VERSION 7 int main(void) { printf("%s %s", STR(VERSION)…