Incorrect version
# Include <stdio. h> void show_bytes (const char * a, unsigned Len) {int I; for (I = 0; I <Len; I ++) printf ("%. 2x ", * (a + I); printf (" \ n ");} int main (void) {short x = 12345; short MX =-X; show_bytes (char *) & X, sizeof (x); show_bytes (char *) & MX, sizeof (short); Return 0 ;}
Because the integer is upgraded when * (a + I) is passed to printf, and the height is filled with the symbol bit when the number of signed characters is upgraded. So print x correctly and print MX Error
Correct version
# Include <stdio. h> void show_bytes (const unsigned char * a, unsigned Len) {int I; for (I = 0; I <Len; I ++) printf ("%. 2x ", * (a + I); printf (" \ n ");} int main (void) {short x = 12345; short MX =-X; show_bytes (unsigned char *) & X, sizeof (x); show_bytes (unsigned char *) & MX, sizeof (short); Return 0 ;}