Monday, 30 April 2012

Program for Call by Reference in C++


#include <iostream>

using namespace std;

void swap(int*, int*);

int main()
{
  int m = 3,
      n = 5;
   
   swap(&m, &n);

  cout << "After swapping: m = " << m << " n = " << n << endl;

  return 0;
}

void swap(int* a_ptr, int* b_ptr)
{
  int temp;

  temp = *a_ptr;
  *a_ptr = *b_ptr;
  *b_ptr = temp;
}

No comments:

Post a Comment