I try to print a nullptr to screen, and:
int* ptrA = nullptr;
std::cout<<ptrA<<"\n"; // print 0
char* ptrB = nullptr;
std::cout<<ptrB<<"\n"; // print nothing, program exit with code 0
... // never execute
I thought the compiler(g++ 4.8.4) may warning me that I should not try to cout a nullptr. the fact is: the program aborted, with '/test has exited with code 0 (0x00000000)', act like it terminals normally.
Why? I mean, if I do something wrong, or what does this designed to be?
thanks
thanks to all, I knew the behavior can be undefined, for a char* to be a string, or to print the address. And was adviced to never do this. I just wonder why the program didn't tell me anything, like warning, assert or exit with a code like -1, anything else. Is it the compiler's designed behavior?