I recently read that
unsigned char x=1;
printf(\"%u\",x);
invokes undefined behaviour since due to the format specifier %u, printf expects
If your platform's int
can represent all values than an unsigned char
can, then the promotion is to int
, otherwise to unsigned int
. So it depends on your platform.
As to "why", that's because you're passing x
as a variable argument, and the rules of variable arguments say that the standard promotions take place (presumably so as to simplify the implementation).