ProgrammingVery hardTCS NQT · Infosys

What is printed? Assume uint16t is 16 bits.

What is printed? Assume uint16_t is 16 bits.
#include <stdint.h>
#include <stdio.h>
int main(void) {
    uint16_t a = 0xFFF0, b = 0x20;
    uint16_t s = a + b;
    int carry = s < a;
    printf("%d %d", s, carry);
}
  1. A. 16 0
  2. B. 65520 1
  3. C. 16 1
  4. D. 240 1

Correct answer: C. 16 1

a + b = 0x10010 wraps to 0x0010 = 16 in a 16-bit type, and the wrap shows as s < a, which is true.

More C Programming questions

Exams that ask this topic