#include <iostream> #include <vector> #include <algorithm> void f(int &n)//pass by reference //void f(int n)//pass by value { n *= 10; } int main(int argc, char *argv[]) { std::vector<int> c = {1, 2, 3, 4}; //for for(int i = 0; i < c.size(); i++) c[i] *= 10; //foreach for(auto &e : c)//pass by reference //for(auto e : c)//pass by value e *= 10; //for_each in algorithm library for_each(c.begin(), c.end(), f); //display for(int i = 0; i < c.size(); i++) std::cout<<c[i]<<" "; std::cout<<std::endl; return 0; }