ProgrammingHardHCL · Tech Mahindra pattern
What is printed?
What is printed?
#define IS_EVEN(x) ((x) % 2 == 0)
#define IS_ODD(x) (!IS_EVEN(x))
int main(void) {
int n = 7;
printf("%d %d", IS_EVEN(n), IS_ODD(n));
}- A. 0 1
- B. 1 0
- C. 0 0
- D. 1 1
Correct answer: A. 0 1
IS_EVEN(7) expands to (7 % 2 == 0) = (1 == 0) = 0 (false). IS_ODD builds on IS_EVEN by negating it: !0 = 1 (true). So: 0 1.
More C Programming questions
- What is printed? c int x = 7; int result = x % 2 == 0 ? x / 2 : x 3 + 1; printf("%d", result);
- What is printed? c #define PRINT(x) printf(#x " = %dn", x) int main(void) { int count = 5; PRINT(count); }
- What is printed? c #define MULTILINE(x) do { x = x 2; x = x + 1; } while (0) int main(void) { int v = 5; MULTILINE(v); printf("%d", v); }
- What is printed? c #define DEBUGPRINT(fmt, ...) printf(fmt, VAARGS) int main(void) { DEBUGPRINT("%d and %dn", 1, 2); }
- What is printed? c #define SAFEDIV(a, b) ((b) != 0 ? (a) / (b) : 0) int main(void) { int x = 10, y = 0; printf("%d", SAFEDIV(x, y)); }
- What is printed? c #if 1 #define VALUE 100 #elif 0 #define VALUE 200 #else #define VALUE 300 #endif printf("%d", VALUE);