A char typically stores characters represented in ASCII. ASCII codes have its MSb set to 0, since it is really a 7-bit code.
However, there's no enforcement of this policy in C or C++. You can set the high bit to 1. This would create a bitpattern that does not correspond to a valid ASCII code.
Nevertheless, it's useful to allow any possible bitstring pattern for a char even though patterns with the MSb equal to 1 are invalid. The reason? There's no byte type!
And even though there's no byte type, it's convenient to have bytes. For example, you may need to read the contents of a file, byte by byte, say, to write a hexdump utility.
Furthermore, people often do computations with characters, such
as:
if ( ch >= 'a' && ch <= 'z' )
ch -= 'a' - 'A' ; // Subtract 32
Notice that we're doing comparisons and arithemtic operations.
For that to make any sense, we need the ability to treat those
bits like numbers.
However, if the high bit of a char were 1, then you'd have to think of the character as a signed quantity. Thus, a char with its MSb set to 1 is considered negative int value.
The reason it exists is simple. chars can be thought of as a signed int, so it makes some sense to have an unsigned version, so you can easily cast unsigned char to larger int types, and zero-extend.
Java, for example, has no unsigned int types. This makes it a pain to cast to larger sizes if you plan to zero-extend an int. Either, you set the MSb to 0 in the shorter int type, cast to the larger, and then reset that bit, or you cast to the larger size, and zero out the upper bits using a mask.
char ch = 'A' ; unsigned char ch2 = static_cast<unsigned char>( ch ) ;The bit patterns don't change when you make this conversion. That is, both ch and ch2 have the same representation. Where things change is when you compare two chars. If it's unsigned char, you treat the bits as if it were 1-byte UB. If it's char, you treat it as if it were 1-byte signed 2C.
Also, when you cast to an unsigned char to an unsigned int, it zero-extends instead of sign-extending.