Is the integer constant’s default type signed or unsigned?

C has different rules for decimal, octal and hexadecimal constants.

For decimal, it is the first type the value can fit in: int, long, long long

For hexadecimal, it is the first type the value can fit in: int, unsigned int, long, unsigned long, long long, unsigned long long

For example on a system with 32-bit int and unsigned int: 0x80000000 is unsigned int.

Note that for decimal constants, C90 had different rules (but rules didn’t change for hexadecimal constants).

Leave a Comment