How to Initialize Multimap with Default Values in C++? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report In C++, a multimap is a container provided by the STL library that stores key-value pairs in an ordered manner. Unlike a map, a multimap allows multiple values to be associated with a single key. In this article, we will learn how to initialize a multimap with default values in C++. Initialize Multimap with Default Values in C++In C++ STL, multimap values are automatically initialized the moment their key is referred for built-in data types. For example, if the type of the value is int, it will be automatically initialized to 0 when the pair is created. If we want to initialize the custom data type value to default values in a multimap, we can define the default values in the data type declaration itself and they will be automatically assigned these values in the multimap. C++ Program to Initialize Multimap with Default ValuesThe below example demonstrates how we can initialize a multimap with default values in C++. C++ // C++ Program to illustrate how to initialize a multimap // with default values #include <iostream> #include <map> #include <vector> using namespace std; // custom data type struct GFG { // member with default value int pointer = -1; // you can also initialize these members to defaalt // values using default constructor }; int main() { // Define keys and default value map<int, GFG> myMap; // creating pairs myMap[1], myMap[2], myMap[3]; // Print the initialized map for (const auto& pair : myMap) { cout << pair.first << ": " << pair.second.pointer << endl; } return 0; } Output1: -1 2: -1 3: -1 Time Complexity: O(N), where N is the size of the map.Auxilliary Space: O(1), initialization does not cost any extra space. Comment More infoAdvertise with us Next Article How to Initialize Multimap with Default Values in C++? S souvik_maity Follow Improve Article Tags : C++ Programs C++ STL cpp-multimap CPP Examples +1 More Practice Tags : CPPSTL Similar Reads How to Initialize a Vector with Default Values in C++? Initialization is the process of assigning the value to the elements of vector. In this article, we will learn how to initialize the vector with default value in C++.The simplest method to initialize the vector with default value is by using constructor during declaration. Letâs take a look at a sim 2 min read How to Initialize a Map with a Range of Key-Value Pairs in C++? In C++, a map is an associative container that stores elements formed by combining a key and a value. In this article, we will learn how to initialize a map with a range of key-value pairs in C++. Initializing a Map with a Range of Key-Value Pairs in C++To initialize a std::map with a range of key-v 2 min read Different Ways to Initialize a Map in C++ Initializing map refers to the process of assigning the initial values to the elements of map container. In this article, we will learn different methods to initialize the map in C++. Let's start from the easiest method:Using Initializer ListThe simplest way to initialize an std::map container is by 3 min read How Can I Sort a Multimap by Value in C++? In C++, std::multimap stores elements as key-value pairs sorted by keys and there is no way to modify it to sort the elements by value but we can create a workaround to achieve it by storing its elements in some other containers that allow us to sort the elements by value.In this article, we will le 4 min read How to Insert into Multimap using make_pair in C++? In C++, a multimap is a container that stores key-value pairs in an ordered manner. Unlike a map, a multimap allows multiple values to be associated with a single key. In this article, we will learn how to insert into a multimap using make_pair in C++. Example Input: myMultimap = {{1, âC++â}, {2, âJ 2 min read Like