cconstantshexunsignedsigned

Unsigned hexadecimal constant in C?


Does C treat hexadecimal constants (e.g. 0x23FE) as signed or unsigned integers?


Solution

  • The number itself is always interpreted as a non-negative number. Hexadecimal constants don't have a sign or any inherent way to express a negative number. The type of the hexadecimal constant is the first one of these which can represent their value:

    int
    unsigned int
    long int
    unsigned long int
    long long int
    unsigned long long int