C++ program to implement Call by reference

C++ program to implement Call by reference, basic C++ program sample coding for college students and fresh job seekers (freshers)

0
697

C++ program to implement Call by reference

CONSTRUCTION:

  1. Read two integers as input.
  2. Pass the numbers to the function using call by reference method of passing.
  3. Perform swapping inside the function.
  4. Display the value of integers& 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