Refefence types - Using of reference
#include <iostream>
using namespace std;
void passByValue(int); //declare our function prototype before main()
int main()
{
//declare and assign the variable num
int num = 3;
std::cout << "In main()" << std::endl;
std::cout << "Value of num is " << num << std::endl;
//call the passByValue
passByValue(num);
std::cout << "Back in main and the value of num is " << num << std::endl;
return 0;
}
void passByValue(int num1)
{
std::cout << "In passByValue()" << std::endl;
std::cout << "Value of num1 is " << num1 << std::endl;
// modify num1, won't impact num
//Inside passByValue, we increment num1 and output its new value, which in this case is 4.
num1++;
std::cout << "num1 is now " << num1 << std::endl;
}PreviousReference types - IntroducingNextReference types - How to differentiate "reference" with "address of a variable"
Last updated