ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
#include <stdint.h>
#include <stdio.h>
int main(void) {
    uint32_t a = 0xFFFFFFF0u, b = 0x20u;
    uint32_t s = a + b;
    int carry = s < a;
    printf("%u %d", s, carry);
}
  1. A. 16 0
  2. B. 4294967312 1
  3. C. 16 1
  4. D. 240 1

Correct answer: C. 16 1

a + b wraps modulo 2^32 to 16, and the wrap is detected by s < a, which is true. The unreduced 4294967312 can never be stored in uint32_t.

More C Programming questions

Exams that ask this topic