C++ references and references parameters
<p>Please look at the code snippet below - I have declared 3 functions (i.e. 1 passing an int and the others passing reference to an int). After executing the program I found that the value of "count" variable after calling function (tripleByReference) has not been changed to reflect its triple (count is still equal to 5). However calling function (tripleByReferenceVoid) modifies the variable but this is due to the fact that changes occurred directly to the variable (count). </p>

<p>I understand that with pass by reference, the caller gives the called function the ability to access the caller's data directly and modify it but that could not be achieved by passing the variable to function (tripleByReference) - Please help me to understand this.</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;

/* function Prototypes */
int tripleByValue(int);
int tripleByReference(int &amp;);
void tripleByReferenceVoid(int &amp;);

int main(void)
{
    int count = 5;

    //call by value
    cout &lt;&lt; "Value of count before passing by value is: " &lt;&lt; count &lt;&lt; endl;
    cout &lt;&lt; "Passing " &lt;&lt; count &lt;&lt; " by value, output is: "
         &lt;&lt; tripleByValue(count) &lt;&lt; endl;
    cout &lt;&lt; "Value of count after passing by value is: " &lt;&lt; count &lt;&lt; endl;

    //call by reference - using int tripleByReference
    cout &lt;&lt; "\n\nValue of count before passing by reference is: " &lt;&lt; count &lt;&lt; endl;
    cout &lt;&lt; "Passing " &lt;&lt; count &lt;&lt; " by reference, output is: " 
         &lt;&lt; tripleByReference(count) &lt;&lt; endl;
    cout &lt;&lt; "Value of count after passing by reference is: " &lt;&lt; count &lt;&lt; endl;

     //call by reference - using void tripleByReference
     tripleByReferenceVoid(count);
     cout &lt;&lt; "\n\nValue of count after passing by reference is: " &lt;&lt; count &lt;&lt; endl;
    cout &lt;&lt; endl;
    system("PAUSE");
    return 0;
}//end main

int tripleByValue (int count) {
    int result = count * count * count;
    return result; 
}//end tirpleByValue function

int tripleByReference(int &amp;count) {
     int result = count * count * count;
     return result; //perform calcs     
}//end tripleByReference function

void tripleByReferenceVoid(int &amp;count) {
     count *= count * count;
}//end tripleByReference function
</code></pre>

<p>Thank you.</p>
