Skip to main content
C++ Code Completion Easy +10 XP

Range-based For

Complete the range-based for loop.

C++Fill in the blank
vector<int> nums = {1,2,3,4,5};
for (___ n : nums) cout << n << " ";

Type the missing code

Show answer and explanation

Answer: int

Range-based for loops use 'type variable : container'. Use auto to let the compiler deduce the type automatically.

Hint: Specify the element type before the variable name.

What this challenge tests

Code Completion in C++: range-for, loops.

Related challenges