ProgrammingHardWipro · Cognizant pattern

What is printed?

What is printed?
#define IS_EVEN(n) ((n) % 2 == 0)
int main() {
    int x = 7;
    if (!IS_EVEN(x))
        printf("odd");
    else
        printf("even");
}
  1. A. Compilation error: macro cannot be negated with !
  2. B. oddeven
  3. C. odd
  4. D. even

Correct answer: C. odd

IS_EVEN(x) expands to ((x) % 2 == 0), fully parenthesized so it's safe to negate: !((7) % 2 == 0) = !(1 == 0) = !0 = 1 (true), so 'odd' prints.

More C Programming questions

Exams that ask this topic