When using STL containers, I am not sure whether an int allocated by the default allocator has been zeroized. The following code indicates ‘yes’ to the question:
#include <map>
#include <iostream>
int main() {
using namespace std;
map<int, int> m;
cout << m[1234] << endl;
}
Since no document has confirmed this, I don’t dare to take it for granted.
You’ll see, inside the implementation of
std::map::operator[], if the element is not found at the index, a new one is inserted and returned:where
mapped_typeis the second type, in your caseint. So yes, it is default-initialized to0, since it’s inserted asmapped_type().