For the following code, on my PC, char \0
will always results in a space (when printing using cout
). However, on my friend's PC, the result of char \0
will always results in a char a
. Code and screenshots are as follows:
#include <iostream>
using namespace std;
// Function main
int main()
{
cout << "xxx" << '\0' << "yyy" << endl;
return 0;
}
Left: on my PC. Right: on my friend's PC.
What's going on here? Why are the results different on different PCs?
PS:
The results will still be different even we share the same executable
exe
file (i.e. compiled on my PC and run on both PCs).We both use visual studio 2010 also with same project character set.
There maybe some buffer overrun here, but please pay attention to the fact that I will always get a
space
while my friend will always get a chara
.It shares the same feature if we both do
cout<<ends
.