Assuming short = 2 bytes, and int = 4 bytes.
-9 is stored in memory in it’s 2’s complement form:
Now for assigning a to iy, unsigned (zero) extension will occur (since the source, ie. a, is of unsigned type.
So iy will look something like this in memory:
this equals 65527
0000 0000 |
0000 0000 |
1111 1111 |
1111 0111 |
Now you should note that any time a char or short type is used in an expression it is first implicitly promoted to int type.
So for first printf:- first a is promoted to int following unsigned extension. And then we have to print it as a decimal integer because of the format specifier. Thus, it will print 65527.
For the second printf, we have to print the same promoted a as an unsigned integer which yields similar results as above: 65527.
And similarly you can reason for the next two printf.