ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
#include <stdint.h>
#include <stdio.h>
int main(void) {
    uint16_t x = 65535;
    int y = x + 1;
    uint16_t z = x + 1;
    printf("%d %d", y, z);
}
  1. A. 65536 0
  2. B. 0 0
  3. C. 65535 0
  4. D. 65536 65536

Correct answer: A. 65536 0

x is promoted to int before the addition, so x + 1 is 65536 in int. Storing that in a uint16_t wraps to 0.

More C Programming questions

Exams that ask this topic