0

I saw the following code somewhere. But I don't know the use of the single colon in the line

auto& it : v 

Does this mean pass the address v to each it? How the for loop access each address in &v ?

#include <iostream> #include <vector> std::vector<int>& addOne(std::vector<int> &v) { for(auto& it : v) { it += 1; } return v; } int main() { std::vector<int> x = {12, -3, 6, 19}; auto y = addOne(x); for (auto& it : y) { std::cout << it << ' '; } std::cout << std::endl; return 0; } 
4

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.