+ 2

I don't understand reference variables

could some one explain it too me please

6th Sep 2017, 3:25 AM
The Kid
The Kid - avatar
3 Respostas
+ 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).
6th Sep 2017, 4:49 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
Variablee are storage containers withon containers, literally, that store information.
6th Sep 2017, 8:46 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 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).
6th Sep 2017, 3:51 PM
Denis Felipe
Denis Felipe - avatar