I'm trying to figure out all different kinds of initialization in C++. Now I'm reading this link: https://en.cppreference.com/w/cpp/language/zero_initialization
In the example of this link, we have such a piece of code:
std::string s; // zero-initialized to indeterminate value
// then default-initialized to ""
As my understanding, the initialization of the global variable is as below:
When we compile the code, the s is zero-initialized, it is put at the .bss segment of the binary file. When we run the binary file (meaning that the kernel is starting to load the binary file into RAM), the s is default-initialized to the empty string "".
Now, we define a function as below:
void func()
{
static std::string s;
}
If we call the function first time, the s will be initialized, this is for sure. But is it still initialized with two methods: first zero initialization, then default initialization, just like the first s?
BTW, I'm working on Ubuntu, X86_64 architecture with the compiler GCC 7.5. If my question is not standardized by C++, you could tell me in the comment and I'll close this question.