[CPP] Call by Reference Using a Reference Parameter Program in C++

It is a simple C++ program on “Call by Reference using a reference parameter“. It will perform a reference operation for the given variables. While compiling the call by reference program, input values are getting using the reference. This CPP program can be used for all kind of students for their lab exams and related tests. It may be useful for their exam purpose.

[Useful: IT Company Details] & [Education Loan Guide]

Call by Reference Using a Reference Parameter

Call by reference is an important technique in the C++ programming. Here we are providing you a simple program to ensure this technique. And this program will let you know about call by reference using a reference parameter. This programs parameter can be passed by its reference itself. Example program is given below,

/*
Title: 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 neg(int &i); // i is a reference prarameter.
int main()
{
clrscr(); //Clears output screen.
int x; //Variables.
x = 10;
cout << x << " Negated is ";
neg(x); // No longer Need the & Operator.
cout << x << "\n";
getch();
return 0;
}
void neg(int &i) //method
{
i = -i; // i is now a reference, don't need *
}