Reference to object

St.Antario

Let we have declaration:

...
int a= 5;
int& b= a;
...

I dont understand, what difference between a and b. I think, that a and b is just adress. But where is this adress in memory? So, let we define a function:

int foo(int& x)
{
    return x;
}
...
foo(a);
foo(b);

What is occuring when foo is calling? I.e. when we'r returning a value we'r going by adress whos in a or b?

NPE

What happens in your code is that a and b are effectively aliases for the same memory location.

Thus

foo(a);

and

foo(b);

are in effect identical.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related