Per Paragraph 8.5/11 of the C++11 Standard:
If no initializer is specified for an object, the object is default-initialized; if no initialization is performed, an object with automatic or dynamic storage duration has indeterminate value. [ Note: Objects with static or thread storage duration are zero-initialized, see 3.6.2. —end note ]
Paragraph 8.5/6 explains what default-initialized means for different variable types:
To default-initialize an object of type T means:
— if T is a (possibly cv-qualified) class type (Clause 9), the default constructor for T is called (and the
initialization is ill-formed if T has no accessible default constructor);
— if T is an array type, each element is default-initialized;
— otherwise, no initialization is performed.
Since T
is neither a class type nor an array type in your case (all your default-initialized variables have type int
), no initialization is performed and the initial value is indeterminate.
Moreover, your program has Undefined Behavior, since it tries to reads the value of an uninitialized variable. Doing so necessitates an lvalue-to-rvalue conversion (although the Standard does not specify this explicitly, requiring so is likely to be intended, see this Q&A on SO), and Paragraph 4/1 of the C++11 Standard mandates:
A glvalue (3.10) of a non-function, non-array type T can be converted to a prvalue.53 If T is an incomplete type, a program that necessitates this conversion is ill-formed. If the object to which the glvalue refers is not an object of type T and is not an object of a type derived from T, or if the object is uninitialized, a program that necessitates this conversion has undefined behavior. If T is a non-class type, the type of the prvalue is the cv-unqualified version of T. Otherwise, the type of the prvalue is T.54