On a platform with 32-bit int and 32-bit unsigned int, what is the type of the literal 0x80000000?
Correct answer
C. unsigned int, because hexadecimal literals take the first type in their list that fits
15 views
C. unsigned int, because hexadecimal literals take the first type in their list that fits
15 views
Unsuffixed hexadecimal constants are considered in the order int, unsigned int, long, unsigned long until one type can represent the value, so 0x80000000 becomes unsigned int on a 32-bit target. The decimal constant 2147483648 instead becomes long, because decimal constants never take an unsigned type unsuffixed. Printing 0x80000000 with %d is therefore technically a type mismatch.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.