A type specifier that requests the unsigned version of an integer type.
int
is implied, so unsigned
is the same type as unsigned int
.unsigned char
is different from the type char
, even if char
is unsigned. It can hold integers up to at least 255.unsigned
can also be combined with short
, long
, or long long
. It cannot be combined with bool
, wchar_t
, char16_t
, or char32_t
.Example:
char invert_case_table[256] = { ..., 'a', 'b', 'c', ..., 'A', 'B', 'C', ... };
char invert_case(char c) {
unsigned char index = c;
return invert_case_table[index];
// note: returning invert_case_table[c] directly does the
// wrong thing on implementations where char is a signed type
}