ProgrammingHardTCS NQT · Wipro

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    unsigned a = 0;
    int r = (a - 1 > 0) && (a++ < 5);
    printf("%d %u", r, a);
}
  1. A. 1 0
  2. B. 1 2
  3. C. 0 0
  4. D. 1 1

Correct answer: D. 1 1

a - 1 wraps to UINT_MAX, so the left operand is true and a++ runs once, leaving a = 1. Since the right operand runs, r is 1.

More C Programming questions

Exams that ask this topic