ProgrammingHardHCL · Tech Mahindra pattern

Assume 32-bit int. What is printed?

Assume 32-bit int. What is printed?
unsigned char a = 200;
unsigned char b = 100;
unsigned char c = a + b;
printf("%u", c);
  1. A. 300
  2. B. 44
  3. C. 255
  4. D. 200

Correct answer: B. 44

a and b are promoted to int for the addition (200+100=300), but the result is then stored back into an unsigned char, which wraps modulo 256: 300 mod 256 = 44. This is well-defined (unsigned types wrap, never undefined), unlike signed overflow.

More C Programming questions

Exams that ask this topic