[CPP] Swapping using Call by reference in C++

C++ program on “Swapping using Call by reference in C++“. It will perform a reference operation for the given variables. While compiling the call by reference program, input values are getting using the reference and swap operations happen. This CPP program can be used for all kind of students like Engineering, Diploma and Arts & Science students for their lab exams and related tests. It may be useful for their exam purpose.

SWAPPING USING CALL BY REFERENCE IN C++

This Swapping C++ program is talking about the call by reference method is done using swapping. There is no parameters and object passing.

[SEE: IT Related Abroad Studies] & [Bike Back Wordings]

PROGRAM:

/*
Title: Swapping in Call by reference
Author: Karthikh Venkat
© http://students3k.com
This website provides lots of useful information for all students.
*/
//Header Files.
#include<iostream.h>
#include<conio.h>
void swap(int &i, int &j); //Swap method
int main()
{
clrscr();
int a, b, c, d;  //Variable declaration
a = 1;
b = 2;
c = 3;
d = 4;
cout << "a and b: " << a << " " << b << "\n";
swap(a, b); // No & Operator needed
cout << "a and b: " << a << " " << b << "\n";
cout << "c and d: " << c << " " << d << "\n";
swap(c, d);
cout << "c and d: " << c << " " << d << "\n";
getch();
return 0;
}
void swap(int &i, int &j) //Method
{
int t;
t = i; // No * operator needed
i = j;
j = t;
}