Take a look at std::numeric_limits<char>::min() and max() . Or CHAR_MIN and CHAR_MAX if you don't like typing, or if you need an integer constant expression.
If CHAR_MAX == UCHAR_MAX and CHAR_MIN == 0 , then unsigned characters (as expected). If CHAR_MAX != UCHAR_MAX and CHAR_MIN < 0 , they are signed (as you can see).
The standard 3.9.1 / 1 provides the absence of other features: "... a simple char can take the same values โโas a signed char or unsigned char; one of them is determined by the implementation."
This tells you whether the char signed or unsigned, and what confuses you. Of course, you cannot call anything to change it: from the POV of the program that it baked to the compiler, even if the compiler has ways to change it (GCC certainly does: -fsigned-char and -funsigned-char ).
The usual way to handle this is that you are going to pass char to int , first pass it through unsigned char . So in your example (int)(unsigned char)mystring[a] . This ensures that you get a non-negative value.
It doesn't really tell you what encoding your implementation uses for char , but I don't think you need to know that. In Microsoft compilers, the answer essentially is that the character encoding "ISO-8859-mutter-mutter" is usually used. This means that characters with 7-bit ASCII values โโare represented by this value, and values โโoutside this range are ambiguous and will be interpreted by the console or another receiver in accordance with the settings of this receiver. ISO Latin 1 unless otherwise indicated.
As a matter of fact, the interpretation of characters depends on the locale, and the locale can be changed and tested using a whole set of materials at the end of the C ++ standard, which I personally have never passed and can not advise on; -)
Please note that if there is a discrepancy between the encoding used and the encoding used by your console, you may encounter problems. But I think that itโs separate from your problem: whether characters can be negative or not, has nothing to do with encodings, is it just that char is signed.