Default values in a Map in C++ STL Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Prerequisite: Map in STLA map is a container which is used to store a key-value pair. By default, In Primitive datatypes such as int, char, bool, float in C/C++ are undefined if variables are not initialized, But a Map is initially empty when it is declared. When this map is accessed with the [ ] (e.g map<int,int> mpp; mpp[1]; ) if the key is not present in the map , it gets added and its value is by default set to 0 (i.e value initialization gets invoked for the int) .To initialize the map with a random default value below is the approach:Approach: Declare a structure(say struct node) with a default value.Initialize Map with key mapped to struct node. Syntax: // For Structure struct Node { int value = -1; } // For Map with every key mapped to default value -1 Map < int, Node > M; Below is the illustration of the Map with a default value -1: CPP14 // C++ program to illustrate a Map // initialize with default value #include <bits/stdc++.h> using namespace std; // Structure Node struct Node { int value = -1; }; // Driver Code int main() { // Map initialize with key value // pair with each pair mapped with // structure Node map<int, Node> Map; // Print the default value of 1 // store in Map cout << Map[1].value << endl; return 0; } Output: -1 Comment More infoAdvertise with us Next Article map emplace_hint() function in C++ STL M maddy1706 Follow Improve Article Tags : C++ STL Practice Tags : CPPSTL Similar Reads map count() Function in C++ STL The std::map::count() in C++ is a built-in function that is used to count the occurrence of the given key in the map container. It is the member function of the std::map container.In this article, we will learn how to use std::map::count() in C++.Syntaxmp.count(key)Parameters key: The value whose oc 2 min read map rend() function in C++ STL The rend() function is an inbuilt function in C++ STL which returns a reverse iterator pointing to the theoretical element right before the first key-value pair in the map(which is considered its reverse end). Syntax: map_name.rend() Parameters:The function does not take any parameter. Return Value: 2 min read map emplace_hint() function in C++ STL The map::emplace_hint() is a built-in function in C++ STL which inserts the key and its element in the map container with a given hint. It effectively increases the container size by one as map is the container that stores keys with the element value. The hint provided does not affect the position t 2 min read map emplace_hint() function in C++ STL The map::emplace_hint() is a built-in function in C++ STL which inserts the key and its element in the map container with a given hint. It effectively increases the container size by one as map is the container that stores keys with the element value. The hint provided does not affect the position t 2 min read map emplace_hint() function in C++ STL The map::emplace_hint() is a built-in function in C++ STL which inserts the key and its element in the map container with a given hint. It effectively increases the container size by one as map is the container that stores keys with the element value. The hint provided does not affect the position t 2 min read unordered_map emplace_hint() function in C++ STL The unordered_map::emplace_hint() is a built-in function in C++ STL which inserts the key and its element in the unordered_map container with a given hint. It effectively increases the container size by one as unordered_map is the container that stores keys with the element value. The hint provided 2 min read Like