Using a reference parameter. : reference parameter « Function « C++ Tutorial






#include <iostream> 
using namespace std; 
 
void f(int &i); // i is a reference parameter 
 
int main() 
{ 
  int val = 1; 
 
  cout << "Old value for val: " << val << '\n'; 
 
  f(val); 
 
  cout << "New value for val: " << val << '\n'; 
 
  return 0; 
} 
 
void f(int &i) 
{ 
  i = 10; 
}
Old value for val: 1
New value for val: 10








7.4.reference parameter
7.4.1.Using a reference parameter.
7.4.2.Use reference parameters to create the swap() function.
7.4.3.Pass by reference by using pointer
7.4.4.Pass by reference using references
7.4.5.Returning multiple values from a function using references
7.4.6.Passing references to objects