Why is it possible to store -32 768 as a short int?
printf("%hd", -32768);
//returns -32768, no compiler errors
printf("%hd", (short int)-32768);
//returns -32768, no compiler errors
short int a = -32768;
printf("%hd", a);
//returns -32768, no compiler errors
printf("%d", -2147483648);
//compiler returned error as it should
And why doesn't short int overflow throw an error in the compiler?
printf("%hd", -32769);
//returns 32767, no compiler errors
while
printf("%d", -2147483648);
//compiler returned error
I am using 64 bit ubuntu 16.04 with the gcc compiler version 5.4.0. It has something to do with the printf function? or I don't understand something.