Promotion and extension of printf sign

I am confused by how type promotion occurs in the case of printf and in general. I tried the following code

unsigned char uc = 255
signed char sc = -128

printf("unsigned char value = %d \n", uc);
printf("signed char value = %d \n", sc);

This gives the following result:

unsigned char value = 255
signed char value = -128

This made me think about how it really is progressing and whether the sign is expanding or not. If the expansion of the mark is completed, the value 255 should be printed as a negative value (-128, remaining the same), and if the expansion without a mark was not performed, then -128 should be printed as a positive value (255 remained the same). Explain, please.

+5
source share
5 answers

If the expansion of the character is completed, the value 255 should be printed as a negative value

- unsigned char, 255, int, int unsigned char - .

, ( , - ). , .

, ( ), .

+4

va_arg .... , . , , int, int unsigned. , printf (un)signed char.

+4

. unsigned char, . , . , , -. , , .

+2

ints - , .

+1
source

The character extension is in progress.

But, since there ucis no sign in the case , since it is equal unsigned char, therefore it remains positive.

0
source

All Articles