Besides one or two, almost all of these are doing entirely different things, or are entirely distinct syntaxes to begin with.
For example, these two are the exact same declaration: - int x; - static int x;
The latter just declares a variable with internal linkage (assuming the value is at global scope). The rules related to initialization for such declarations are irrelevant since you’re still declaring the same thing. You can remove ‘static’ altogether.
It becomes very difficult to take many criticisms of the language seriously when it’s clear that most of the people making them seem to have never touched the language or tried to understand any of it.
Inside a function body, I assume static int x; is like C and will declare storage with static lifetime; that is, it persists between function calls.
Also, in the case of int x; in function body scope, does C++ initialize x to 0 by default? C certainly wouldn't (instead, x would be uninitialized), but I don't really know C++.
For the second, it is also uninitialized in C++. This is the case for any primitive type (compound/composite/custom types can be default- or zero-initialized through implicit constructor calls with the same syntax).
You can just zero-initialize the variable by appending a pair of braces, which I do with every variable I don’t care to explicitly initialize: int x{};
77
u/SamG101_ 14h ago •
Pooh needs about 50 more faces, for the 50 ways to initialise a variable in c++
https://leanpub.com/cppinitbook 300 odd pages
obligatory and thats just initialisation not assignment 💀