ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    unsigned char c = 255;
    c += 1;
    printf("%d", c);
}
  1. A. 0
  2. B. 1
  3. C. 256
  4. D. 255

Correct answer: A. 0

c + 1 is 256 in int, and storing it back in unsigned char wraps the value to 0.

More C Programming questions

Exams that ask this topic