Hash map display related

// CPP program to demonstrate the
// unordered_map::end() function
// returning the elements along
// with their bucket number
#include
#include
#include <unordered_map>

using namespace std;

int main()
{
unordered_map<string, int> marks;

// Declaring the elements of the multimap 
marks = { { "Rohit", 64 }, { "Aman", 37 }, { "Ayush", 96 } }; 

// Printing all the elements of the multimap 
for (auto iter = marks.begin(); iter != marks.end(); ++iter) { 

	cout << "Marks of " << iter->first << " is "
		<< iter->second << " and his bucket number is "
		<< marks.bucket(iter->first) << endl; 
} 

return 0; 

}
How this for loop is printing bucket no.3 two times since at every bucket it takes a pair and then it reaches to next bucket so how this for loop is able to take two pairs
// CPP program to demonstrate the
// unordered_map::end() function
// returning all the elements of the multimap
#include
#include
#include <unordered_map>
using namespace std;

int main()
{
unordered_map<string, int> marks;

// Declaring the elements of the multimap 
marks = { { "Rohit", 64 }, { "Aman", 37 }, { "Ayush", 96 } }; 

// Printing all the elements of the multimap 
cout << "marks bucket contains : " << endl; 
for (int i = 0; i < marks.bucket_count(); ++i) { 

	cout << "bucket #" << i << " contains:"; 

	for (auto iter = marks.begin(i); iter != marks.end(i); ++iter) { 
		cout << "(" << iter->first << ", " << iter->second << "), "; 
	} 

	cout << endl; 
} 
return 0; 

}
i am able to understand this code with two for loops but i am not able to understand how a single for loop is able to print both pairs of single bucket

hey @bansalpriyal45, it is due to internal working of unordered map only. A bucket can be assigned to 2 or more contents. I am sharing you link from official C++ website. You can observe the same thing is happening in their examples too.
http://www.cplusplus.com/reference/unordered_map/unordered_map/bucket/

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.