+ 2
references?
In the following code can someone please explain why they are using references and what exactly they are referencing when they say Const string& name https://code.sololearn.com/cHBTnR1sywn4/#cpp
11 Answers
+ 3
References are used to avoid copying a whole object which creates an overhead. Instead of making a copy, the address of the object in memory is passed into the function. This also means that any changes you make to that object will be made to the original object, hence you use const when you want to make sure you don't make any chnages to that object if you dont need to.
+ 1
You're obviusly speaking about parameter... what you've written means that you're passing a string by address and that the variable you're passing cannot be modified ("const" stand for constant) by the function
passing a parameter by address will make the esecution faster but give the chance to the function you're passing the parameter to, to change the variable. that's why you pass it as "const"
0
refrences are memory address followed by & sign
0
Whoever is downvoting
If the answer is wrong.
Care to explain, why it is wrong?
0
Or do you enjoy downvoting users for fun?
- 1
but why is it used in that context
- 1
I don't see what is actually being referenced
- 1
Hey Brian,
I just made a code with vectors!
I will link it later with some resources.
- 1
The code looks good!
- 1
Here is my Abilities code
I made it in order to get better at using vectors.
https://code.sololearn.com/cMMcFCTL93kQ
- 2
Vector is a class
you are using objects to store things.
myfarm is an object you made from that class.
you are "refering" to it to output what is stored inside.



