Here's an example that shows two functions with the same body but with one using a reference and the other simply a copy of the value.
Code:
#include <iostream>
using namespace std;
void change_value (int &num)
{
num = 563;
}
void not_changing_value (int num)
{
num = 432;
}
int main ()
{
int number = 1;
cout << number << endl;
change_value(number);
cout << number << endl;
not_changing_value(number);
cout << number << endl;
return 0;
}
A reference is simply a pointer that dereferences itself and can be used as if it was a "normal" variable.
The function change_value could therefore be written with pointers as
Code:
void change_value (int *num)
{
*num = 563;
}
And the call to the function would have to be changed to
Code:
change_value(&number);
in main.