W.A.7.1 o parameters

Worksheet W.A.7.1                                                                   Name  _______________________

 

PARAMETERS

 

Predict the output of this program:

 

// parameters.cpp

 

// A short program to test understanding of parameter passing

 

#include <iostream.h>

 

void one (int, int);

void two (int &, int &);

void three (int &, int &);

void print (const int &, const int &);

 

main ()

{

       int a = 2, b = 5;

      

       print (a,b);

       one (a,b);

       print (a,b);

       two (a,b);

       print (a,b);

       three (a,a);     // unusual call

       print (a,b);

       return 0;

}

 

void one (int s, int t)

{

       s *= 2;

       t += s;

       print (s,t);

}

 

void two (int &g, int &h)

{

       g *= 2;

       h += g;

}

 

void three (int &c, int &d)

{

       c *= 2;

       d *= 2;

}

 

void print (const int &num1, const int &num2)

{

       cout << num1 << "   " << num2 << endl;

}