since C language using the char as integer internally(correspondent ASCII is stored). for internal calculation we can use signed and unsigned char.
other than that, any other use??
since C language using the char as integer internally(correspondent ASCII is stored). for internal calculation we can use signed and unsigned char.
other than that, any other use??
signed
and unsigned
char
are first and foremost just small integers. Do you need to store a large quantity of small numbers (in the range [-127, +127]¹ or [0, 255])? You can use an array of signed
or unsigned
chars and save memory compared to pretty much any other type. That's what is done for e.g. images - a grayscale image is generally stored as an array of unsigned char
(and an RGB image is generally stored as an array of 3 unsigned char
components).
The second usage of char
is for character strings, which you probably already saw; notice that char
is a distinct type from both signed char
and unsigned char
, and its signedness is implementation defined. This is stupid and inconvenient in many situations - and leads to sad stuff such as the mandatory cast to unsigned char
when calling functions of the toupper
/isupper
family.
Finally, char
& co. are defined as the "underlying storage" of the C abstract machine. sizeof(char) == 1
by definition, and any type can be aliased through a (signed|unsigned)? char
pointer to access its underlying bit representation.
signed char
by the standard, as it still allows sign and magnitude representation; more realistic, on any real-world machine of this century it will be at least [-128, 127].