// paramPassing2.cc
// P. Conrad CISC181 03/02/06
// in which we introduce, additionally
// "true" pass by reference

#include <iostream>
using namespace std;

// pass-by-value

int foo(int x)
{
  x=4;
  return 2*x;
}

// simulated pass-by-reference (passing a pointer by value)
int bar(int *y)
{
  int a;
  a=2*(*y);
  (*y)++;
  return a+(*y);
}

// true pass-by-reference
int fum(int &z)
{
  z++;
  cout << "z=" << z << endl;
  return (z);
}

int main(void)
{
  int a, b, c, x, y, z;
  x=3;
  a=foo(7);
  b=bar(&a);
  c=foo(bar(&x));
  y = fum(a);

  cout << "a=" << a << " b=" << b << " c=" << c << endl;
  return 0;
}

