char* s = 0;
Initializing a char
pointer that points to null.
char *t = "";
Initializing a char
pointer with a string literal, it's practically empty as
is a null character used to terminate C-style strings, what you have done is effectively equivalent to std::string t = "";
. The following code:
char *t = "hello";
cout << t << endl;
...would have resulted in:
hello
I have to point out that you invoked undefined behavior by passing a null pointer to cout
, your program most likely crashed after cout<<s<<endl;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…