1.Change elements through references
IntermediateWrite void double_all(std::vector<int>& v) that doubles every element in place, and use it on {3, 7, 10}.
Show hint
Take the vector by reference, and loop with int& so you change the real elements.
Show solution
#include <iostream>
#include <vector>
void double_all(std::vector<int>& v) {
for (int& x : v) {
x *= 2;
}
}
int main() {
std::vector<int> v = {3, 7, 10};
double_all(v);
for (int x : v) std::cout << x << ' ';
std::cout << '\n';
}6 14 20