I always thought the following code
std::map<int, int> test; std::cout << test[0] << std::endl;
will print a random value as it will create a uniform value inside the map. However, it turns out that the created int is always always initialized to zero. And standard built-in types are also initialized to zero under certain circumstances.
Question: when is zero initialization performed for standard types (int / char / float / double / size_t)? I am sure that if I declare int i; in the middle of nowhere, it will contain random data.
PS Question about the C ++ 03 standard. The reason for the question is that now I am not sure when I had to provide initialization for built-in types such as int / float / size_t or when they can be safely skipped.
source share