What is the output of this C code
void main()
{
unsigned int x = -5;
printf("%d", x);
}
Answer: C
Correct answer: -5
The bits assigned to x are the two’s-complement pattern of \(-5\); storing them in an unsigned int changes the interpretation, not the bits. %d then asks printf to read those same bits back as a signed int, so -5 is what appears. Using %u would print 4294967291 on a 32-bit int.
Please log in or register to report this question.