Neither printf() nor any other function will, as a side-effect, reset uninitialized variables. The C++ standard does not guarantee the behavior of uninitialized variables, so your code is "taking advantage" of behavior that is undefined by the standard. Said another way, you shouldn't need to be concerned about why it behaves differently in the two cases because neither is correct since there is no definition of "correct" in this case.
It you really want to know why, you would probably need to look at the assembler code generated by the compiler to understand why in one case the variable always seems to be non-zero and in the other always seems to be zero.