I have read on Stack Overflow that global/static variables are initialized to their default value (0).
I also read somewhere else (not sure tho), that class variables (non-static) are also initialized to 0. Is this true?
Specifically, I am wondering whether my pointers are by default initialized to nullptr.
I tried compiling on g++ and clang and both seem to initialize them to nullptr.
#include <iostream>
struct Foo {
int *ptr;
};
int main() {
Foo f;
std::cout << f.ptr;
}
printed:
0
If it's only my compiler doing it, is there any way I can tell my compiler not to do this (using some compiler flag)?