#include <iostream.h>
// Function prototypes...
void Func1(int Num);
void Func2(int &Num);
int main(void)
{
int A = 3;
cout << "Before Func1: A = " << A << endl << endl;
Func1(A);
cout << "After Func1: A = " << A << endl << endl;
Func2(A);
cout << "After Func2: A = " << A << endl;
return(0);
}
void Func1(int Num)
{ // Function that adds 2 to its
// Pass-By-Value parameter...
Num = Num + 2;
}
void Func2(int &Num)
{ // Function that adds 2 to its
// Pass-By-Reference parameter...
Num = Num + 2;
}
C++ / PRACTICAL TUTORIAL
Pass by Reference in C++ functions
Advertisement
This sample C++ program, demonstrates Pass by Reference functions.
From the community
No archived comments on this tutorial.