Without an actual program, we can only guess whether the output was produced by a program that initialized that pointer to zero (by the above-mentioned zero-init) or simply got zero as a perfectly reasonable garbage value to be found in memory.
Edit: didn't see the previous 3 posts while doing mine :+)
I want to understand WHY the zero initialization took place there.
Did you read the documentation? There are other types of initialisation, all documented on cppreference.
If you didn't initialise it to something (nullptr), what were you expecting? How does it being garbage ( like you must have been expecting) help you? Would it not make sense to initialise it to nullptr? Then that means it isn't pointing to anything, and you could make use of that in a test condition.
Could you use a smart pointer instead of a raw pointer?
Did you read the documentation? There are other types of initialisation, all documented on cppreference.
None of the following matches my situation
1) For every named variable with static or thread-local storage duration that is not subject to constant initialization (since C++14), before any other initialization.
2) As part of value-initialization sequence for non-class types and for members of value-initialized class types that have no constructors.
3) When a character array is initialized with a string literal that is too short, the remainder of the array is zero-initialized.
If you didn't initialise it to something (nullptr), what were you expecting?
If I don't initialize something, I expect it to be garbage, not auto-initialized.
Could you use a smart pointer instead of a raw pointer?
Garbage doesn't mean random. Zero is a possible "garbage value".
Modern operating systems often zero-initialize memory before giving it to a process to prevent the program from being able to read left over memory values from other programs because that could be a security concern.
I believe Visual C++ zero-initializes a lot of things that would otherwise be left uninitialized when compiling in debug mode. If you're using this compiler try compiling in release mode and see if there is a difference.
You've lost the battle of the optimizer. You class data member is not initialized. In fact, it's not even created or stored anywhere. VC++ just arbitrarily decided the uninitialized pointer it was asked to feed to std::cout was equal to the nullptr.
You've lost the battle of the optimizer. You class data member is not initialized. In fact, it's not even created or stored anywhere. VC++ just arbitrarily decided the uninitialized pointer it was asked to feed to std::cout was equal to the nullptr.
I put the pointer inside an if-statement before couting it.