C++ program to implement Call by address

C++ program sample coding for college students and fresh job seekers

0
743

C++ program to implement Call by address

CONSTRUCTION:

  1. Read two integers as input.
  2. Pass the address to the function using call by address method of passing.
  3. Perform swapping inside the function.
  4. Display the value of integers.
  5. Terminate the program.

PROGRAM:

#include<iostream.h>

void swap(int *a,int *b)
{
 int t;
 t=*a;
 *a=*b;
 *b=t;
}
void main()
{
 int x,y;
 cin>>x>>y;
 cout<<”Before Swapping:”<<x<<y;
 swap(&x,&y);
 cout<<”After Swapping:”<<x<<y;
}

Leave a Reply