ProgrammingVery hardGATE CS · TCS NQT

What is printed?

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

Correct answer: D. 0 255

d holds 255 after conversion, and c is promoted to -1, which is not equal to 255. The comparison yields 0, and (int)d is 255.

More C Programming questions

Exams that ask this topic