C++ map size() FunctionC++ map size() function is used to find the number of elements present in the map container. SyntaxMember type size_type is an unsigned integral type. ParameterNone Return valueIt returns the number of elements present in the map. Example 1Let's see a simple example to calculate the size of the map. Output: num map contains 4 elements. In the above example, map num contains 4 elements. Therefore ,size() function returns 4 elements. Example 2Let's see a simple example to calculate initial size of map and size of map after adding elements. Output: Initial size of map = 0 Size of map after inserting elements = 5 In the above example, first map is empty. Hence, size() function will return 0 and after inserting 5 elements it will return 5. Example 3Let's see a simple example. Output: x => 100 y => 200 z => 300 In the above example, It simply use the size() function in while loop and prints the elements of map until the size of map. Example 4Let's see a simple example. Output: Enter three sets of name and number: Nikita 1001 Deep 2001 Aashi 3001 Size of phone map is:3 List of telephone numbers: Aashi 3001 Deep 2001 Nikita 1001 In the above example, the program first creates phone map interactively with three names. Then, it displays the total size of phone map and all the names and their telephone numbers available in the map. Next TopicC++ Map |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India