Why is the hexadecimal output of-10 ffffff6?

-sharpinclude <stdio.h>
int main()
{
    short int x = -10;
    //  - 1000 0000 0000 1010
    //  - 1111 1111 1111 0101
    //  - 1111 1111 1111 0110
    //         F    F    F    6
    //  - fffffff6, 4
    printf("%x\n", x);
}

I just started to read the C language, but I don"t quite understand the
solution. Thank you

.
Mar.23,2021

it is wrong to determine that the length of the parameter n is 4 bytes with the printing result of printf ("x", n) ) ff f6 .

according to the C language specification, the x modifier of the printf function is converted to the unsigned int type by default when no length is specified.
that is, in this case printf ("x", n) is equivalent to printf ("x", (unsigned int) n) ).

to print the parameter n to the original data type, you can do so

printf("%hx", n);
// 
printf("%x", (unsigned short)n);

refer to
[1] C printf, http://www.cplusplus.com/refe.


The

language standard only specifies at least a few bytes of the type and the size relationship between several types. The exact size of the
type is determined by the compiler.

< hr >

Li Yi's answer is correct. You did not use the correct% x modifier to output, resulting in actually pressing unsigned int output.
if you change the modifier of the output and the result is still not as expected, you can explain it with my answer above.


-sharpinclude <stdio.h>

int main(void) { 
    
    char a=-10,b=1,e=2,d=4;
    long long c=-10;
    int sizea=sizeof(a);
    int sizec=sizeof(c);
    printf("%x,%d\n%x,%d\n",a,sizea,c,sizec);
    printf("%x,%d\n%x,%d",*((unsigned int*)&a),sizea,*((unsigned int*)&c),sizec);
    return 0;
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e494ce-44d0f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e494ce-44d0f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?