Try this:
std::cout << (int)U << std::endl;
std::cout << "The size in bytes of this variable is: " << sizeof(U) << std::endl
<< std::endl;
std::cout << (int)S << std::endl;
std::cout << "The size in bytes of this variable is: " <<sizeof(S) << std::endl << std::endl;
The explanation is so simple: when the type is char
, cout
is trying to produce a symbolic output which is whitespace
for 255 or a pretty-like triangle for 127. When the type is int
, cout just prints the value of the variable. For example in C:
printf("%d", 127) // prints 127
printf("%c", 127) // prints triangle, because %c formatter means symbolic output