0

Ok I feel like this may be a dumb question, but I'm putting it out there anyway. It's been a while since I've worked with C++.
What characters does C++ print for negative values of char?
Positive values seem to follow ASCII, but ASCII is only 128 characters. So where are the others from?

#include<iostream>

using namespace std;

int main() {

   char myChar = 127;
   
   while(myChar > -128) {
      cout << static_cast<int>(myChar) << " " << myChar << endl;
      myChar--;
   }
   cout << static_cast<int>(myChar) << " " << myChar << endl;

   return 0;
}
2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by EvolutionFallen
0

>Positive values seem to follow ASCII, but ASCII is only 128 characters. So where are the others from?
It really depends on the character set your system is using, but probably Unicode or some form of extended ASCII.

Edited by Narue: n/a

0

Thanks Narue. I guess it must be extended ASCII (didn't know that exists) because if I set char > 127 or < -128 the program does funny things.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.