unordered_map begin() in C++ Last Updated : 03 Dec, 2021 Comments Improve Suggest changes 6 Likes Like Report The unordered_map::begin() is a built-in function in C++ STL which returns an iterator pointing to the first element in the unordered_map container or in any of its bucket. Syntax for first element in unordered_map container: unordered_map.begin() Parameters: This function does not accepts any parameters. Return Value: The function returns an iterator pointing to the first element in the unordered_map container. Note: In an unordered map, there is no specific element which is considered as the first element. Below program illustrate the above function. CPP // CPP program to demonstrate the // unordered_map::begin() function // when first element of the container // is to be returned as iterator #include <bits/stdc++.h> using namespace std; int main() { // Declaration unordered_map<std::string, std::string> mymap; // Initialisation mymap = { { "Australia", "Canberra" }, { "U.S.", "Washington" }, { "France", "Paris" } }; // Iterator pointing to the first element // in the unordered map auto it = mymap.begin(); // Prints the elements of the first element in map cout << it->first << " " << it->second; return 0; } Output: France Paris Syntax for first element in unordered_map bucket: unordered_map.begin( n ) Parameters: The function accepts one mandatory parameter n which specifies the bucket number whose first element's iterator is to be returned. Return Value: The function returns an iterator pointing to the first element in the n-th bucket. Below program illustrate the above function. CPP // CPP program to demonstrate the // unordered_map::begin() function // when first element of n-th container // is to be returned as iterator #include <bits/stdc++.h> using namespace std; int main() { // Declaration unordered_map<std::string, std::string> mymap; // Initialisation mymap = { { "Australia", "Canberra" }, { "U.S.", "Washington" }, { "France", "Paris" } }; // Iterator pointing to the first element // in the n-th bucket auto it = mymap.begin(0); // Prints the elements of the n-th bucket cout << it->first << " " << it->second; return 0; } Output: U.S. Washington Create Quiz Comment S Striver Follow 6 Improve S Striver Follow 6 Improve Article Tags : Misc C++ STL CPP-Functions cpp-unordered_map cpp-unordered_map-functions +2 More Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like