'what does char() print out in C++
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;
}
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Wisblade |
