ProgrammingHardIBM · Deloitte pattern

What is printed?

What is printed?
int main(void) {
    char c = 200;
    printf("%d", c);
}
  1. A. Implementation-defined: on a platform where plain char is signed (the common case), 200 overflows the signed char range (-128 to 127) and the stored/printed value is typically -56
  2. B. -200
  3. C. It is always 56 on every platform
  4. D. 200

Correct answer: A. Implementation-defined: on a platform where plain char is signed (the common case), 200 overflows the signed char range (-128 to 127) and the stored/printed value is typically -56

Whether plain `char` is signed or unsigned is implementation-defined in C. On the common case (signed char, 8 bits, range -128..127), assigning 200 (outside that range) results in an implementation-defined conversion — typically wrapping to 200-256=-56 on two's-complement systems — rather than storing 200 directly, which doesn't fit.

More C Programming questions

Exams that ask this topic