+ 2
I don't understand reference variables
could some one explain it too me please
3 ответов
+ 14
Reference variables are basically aliases to the variables they reference. E.g.
int x = 5;
int &y = x;
This means that y is simply another name for variable x. Both y and x share the same address, and any changes done to y will reflect on x (because, as has been mentioned, y refer to x, they are the same).
+ 3
Variablee are storage containers withon containers, literally, that store information.
+ 1
Let's say you have some money (int money), and your child wants to buy something. He doesn't store any money with him, but he can point at you to pay stuff for him (int& money_ref). Any operation your child does, will increase or decrease your money, because he only redirects to you to handle the operation, but doesn't actually store any value (other than your address).