Pass by Reference in C++ functions
By: Grant Braught
This sample C++ program, demonstrates Pass by Reference functions.#include
// 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;
}
Archived Comments
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Calculating total based on the given quantity and price in C++
Sorting an array of Strings in C++
Matrix using nested for loops in C++
Compute the square root of the sum of the squares of an array in C++
Calculate average using Two-Dimensional Array in C++
Two-Dimensional Array Manipulation in C++
Compiling and Linking Multiple Source Files in C++
Escape Sequences for Nonprintable Characters in C++
Using the Built-in Arithmetic Types in C++