Thursday, 7 May 2015

[C++] CALL BY ADDRESS AND CALL BY REFERENCE FOR SWAPING


CALL BY ADDRESS




PROGRAM

#include <iostream>
#include <conio.h>

void main()
{
int a = 10, b = 5;
swap(&a,&b);
cout << a << "&" << b;

}

void swap(int *m,int *n){
int temp;
temp = *m;
*m = *n;
*n = temp;
}

OUTPUT


  • 5&10


                              CALL BY REFERENCE


PROGRAM

#include <iostream>
#include <conio.h>

void main()
{
int a = 10, b = 5;
swap(a,b);
cout << a << "&" << b;

}

void swap(int &m,int &n){
int temp;
temp = m;
m = n;
n = temp;
}


OUTPUT

  • 5&10

No comments:

Post a Comment