I saw this from C Primer Plus, the 6th edition, Review Questions in Chapter 3.
Answer in Appendix A:
Notice d.0XAA, my answer is
That book is incorrect. As per C11 126.96.36.199, the type of integer constants of hexadecimal are determined from this table:
Suffix ... Octal or Hexadecimal Constant None ... int unsigned int long int unsigned long int long long int unsigned long long int u or U ... unsigned int unsigned long int unsigned long long int
0xAA has no suffix so the top part of the above table is what applies. Meaning: the compiler will first check if the value can fit in an
int. If it doesn't fit, it will check if it will fit in an
unsigned int and so on.
On any known implementation of C, the value
0xAA will certainly fit inside an
int. The correct answer to the question is
However, had the constant been
0xAAu, the bottom part of the cited table would have applied and the result would have been an