ProgrammingModerateTCS NQT · Wipro

What is printed?

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

Correct answer: B. 1

c goes from 254 to 255, which makes the loop body run once, and the next increment wraps c to 0, so the loop stops. The count is 1.

More C Programming questions

Exams that ask this topic