Search code examples
c++ascii

giving integer value to character data type in c++ and how ascii symbols (code >127) get printed?


When we perform the following code:

char p = 0 ;
cout << p << endl ;

Does this mean that p stores the symbol whose ASCII code is 0? (Which is NULL Character, and therefore nothing gets printed?)

The range of character data type is -128 to 127. And ASCII 0 to 256. So, how those ASCII symbols (code > 127) get printed?

From the commented dupe links, I cant understand, the above part of the question.


Solution

  • Yes, 0 is ASCII NUL.

    char is signed on some platforms and unsigned on others. Standard ASCII only has a range of 0 to 127. The rest, whether they are 128 to 255 or -128 to -1, are sometimes called Extended ASCII and are less consistent across systems.