I tried to find documentation on this but there doesn't seem to be any definite answers to this. I tried in an example program, and it seems to \0
but is this reliable behavior? What does char() initialize to and is this in the C standard.
int main()
{
std::cout<<char()<<std::endl;
return 0;
}
CodePudding user response:
The fact that char()
returns \0
is normal, and it's reliable (integer variables are initialized to 0 with such a syntax, and pointers are initialized to nullptr
). For example, unsigned short int()
will also returns 0. For a char
, it's obviously not the character "0", but the NUL
character.
Then, when trying to print that, you're trying to print a char
that is used, in char*
strings, to mark the end of the string... So without surprise, it isn't printed at all, even as a single character.