My advice would be to understand references first, separate from the context of function parameters.
Here's some sample code:
int a = 5;
int &b = a;
Now, a
and b
are both labels for the same variable. This code is actually identical to:
int b = 5;
int &a = b;
Anywhere you subsequently use a
, you can use b
instead; no exceptions to this rule. The key point is that you can have multiple identifiers that identify the same variable.
Moving onto the function context. If you have:
int a;
foo(a);
and
foo(int &b)
{
then main
's a
and foo
's b
are both labels for the same variable. Doing an operation on b
in foo
is exactly the same as doing the operation on a
in main
. They are both the same variable, just with different names. Similar to how Prince William and the Duke of Cambridge are the same guy.