Showing posts with label Call By Value and Call By Reference. Show all posts
Showing posts with label Call By Value and Call By Reference. Show all posts

Tuesday 15 April 2014

Call By Valuse and Call By reference

#include <iostream.h>

int f1 (int, int, int);
int f2 (int&, int&, int&);
int f3 (int, int&, int);

void main () {
  int i, j, k;

  i=1;
  j=2;
  k=3;

  cout << endl;
  cout << "Initial values of i, j, and k are: " 
    << i << ", " << j << ", and " << k << endl << endl;
  cout << "f1(i,j,k) = " << f1(i,j,k) << endl;
  cout << "Values of i, j, and k after the call to f1 are: " 
    << i << ", " << j << ", and " << k << endl << endl;
  cout << "f2(i,j,k) = " << f2(i,j,k) << endl;
  cout << "Values of i, j, and k after the call to f2 are: " 
    << i << ", " << j << ", and " << k << endl << endl;
  cout << "f3(i,j,k) = " << f3(i,j,k) << endl;
  cout << "Values of i, j, and k after the call to f3 are: " 
    << i << ", " << j << ", and " << k << endl;
}

int f1 (int x, int y, int z) {
  x=x+5;
  y=y+5;
  z=z+5;
  return(x+y+z);
}

int f2 (int& x, int& y, int& z) {
  x=x+5;
  y=y+5;
  z=z+5;
  return(x+y+z);
}

int f3 (int x, int& y, int z) {
  x=x+5;
  y=y+5;
  z=z+5;
  return(x+y+z);
}

Comment

Comment Box is loading comments...