passing a vector to a function c++

C++
// C++ program to demonstrate how vectors 
// can be passed by reference. 
#include<bits/stdc++.h> 
using namespace std; 
   
// The vect is passed by reference and changes 
// made here reflect in main() 
void func(vector<int> &vect) 
{ 
   vect.push_back(30); 
} 
   
int main() 
{ 
    vector<int> vect; 
    vect.push_back(10); 
    vect.push_back(20); 
   
    func(vect); 
  
    for (int i=0; i<vect.size(); i++) 
       cout << vect[i] << " "; 
   
    return 0; 
} 
// C++ program to demonstrate that when vectors 
// are passed to functions without &, a copy is 
// created. 
#include<bits/stdc++.h> 
using namespace std; 
   
// The vect here is a copy of vect in main() 
void func(vector<int> vect) 
{ 
   vect.push_back(30); 
} 
   
int main() 
{ 
    vector<int> vect; 
    vect.push_back(10); 
    vect.push_back(20); 
   
    func(vect); 
   
    // vect remains unchanged after function 
    // call 
    for (int i=0; i<vect.size(); i++) 
       cout << vect[i] << " "; 
   
    return 0; 
} 

Source

Also in C++: