ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    unsigned char c = 200;
    if (c * 2 > 300) puts("big");
    else puts("small");
}
  1. A. small
  2. B. big
  3. C. both
  4. D. none

Correct answer: B. big

c is promoted to int before the multiplication, so c * 2 is 400 and not wrapped to a byte. The comparison 400 > 300 is true.

More C Programming questions

Exams that ask this topic