When you pass a variable by value to a function, it makes a copy of that value - it doesn't send the variable itself.
So, for example:
1 2 3 4
|
a = 5;
cout << a;
someFn(a);
cout << a;
|
would make a = 5, display the value of 'a' (which is 5), send a copy of 'a' (which is still 5) to someFn(), and then display 'a' again -- which would still be 5, because someFn() didn't do anything to a itself. It only did something to a copy of 'a'.
------------
In your program, a copy of int2 is sent to function(), so function receives the value 5. Because it is written as function(int int1), the value received is given the name int1. Then you set int1 to 10, and then display that value. Then you return int1 -- but that doesn't do anything because nothing will contain the value returned by function(). ( If you wanted int2 to hold the value returned by int1, you would need to write int2 = function(int2); )
Now, remember that function() received a copy of int2, not the variable itself. So int2 is still unchanged by being passed by value. Thus, displaying the value of int2 displays a 5.
------------
When you pass a pointer to a function, you are giving the function a copy of the location of the variable, so that it can do something to the value at that location. This is a way to change the variable from within the function.