I know that local variables in C & C++ aren't automatically initialized & if no initial value is given to them they have garbage values. I also know that global & static variables are by default initialized to zero. Use of uninitialized variable results in undefined behavior in C++.
But recently I tried following simple C++ program on various implementations of C++ & all gives me 0 as output.
#include <iostream>
int main()
{
int u;
std::cout<<u<<'\n';
}
Output:
CodeBlocks 13.12 IDE: 0
Orwell Dev C++ 5.8.3: 0
Ideone.com: 0 (visit this: http://ideone.com/zWrgwo)
Is it true that modern compilers automatically initializes local variables to 0? or such type of program still represents undefined behavior ? Is it guaranteed to see 0 as output on every modern implementation of C++ always?