initializer_list in C++
Level 4157 keystrokes
A function that takes an initializer_list<int> accepts brace lists of any length; it is called with 3 and then 5 values and prints them.
C++ code
// initializer_list<int> receives a {...} list of ints of any length1void printList(initializer_list<int> list) { // It can be iterated with a range-based for loop2 for (int n : list) { // Print each value followed by a space3 cout << n << " ";4 } // End the line after the list5 cout << endl;6}7 // Three values: prints 1 2 38printList({1, 2, 3});// Same function with five values: prints 10 20 30 40 509printList({10, 20, 30, 40, 50});Output
1 2 3 10 20 30 40 50
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C++ code and how often they appear.
<× 7,× 6;× 4(× 4)× 4{× 4}× 4"× 2_× 1:× 1