call by address in c++

/*In call by address we pass pointer(*) in the argument in the difinition and while calling the function we pass address of the variable*/

using namespace std;
void swap(int *,int *);
int main()
    int a,b;
    cout<<“Enter A and B “<<endl;
    cout<<“Before swapping “;
    cout<<” A “<<a<<” B “<<b<<endl;
    swap(&a,&b);//here we are passing address of a and b thats why we are using & operator with a and b.
    cout<<“After swapping “;
    cout<<” A “<<a<<” B “<<b;

void swap(int *x,int *y)
    int temp;


Enter A and B 
Before swapping  A 9 B 6
After swapping  A 6 B 9

Leave a Comment

Your email address will not be published. Required fields are marked *

Open chat