Passing parameters

If parameters are passed by reference, like for the function dublicate(), variable values outside the function can be changed. Section 10.3 contains an example from the Tango world.

#include <iostream>
using namespace std;
//
// passing parameters by reference
//
void duplicate (int& a, int& b, int& c)
{
  a *=2;
  b *=2;
  c *=2;
}
//
// passing parameters by value
//
int add (int a, int b, int c)
{
  return a + b + c; 
}

int main ()
{
  int x=1, y=3, z=7;
  int result; 
  result = add (x, y, z);
  cout << " sum " << result << "\n";
  duplicate(x, y, z);
  cout << "x=" << x << ", y=" << y << ", z=" << z;
  return 0;
}