I got this question on my exam
In a passing parameter, during a function call, the parameters are copied => call to the copy constructor for each parameter. Suppose a List is passed as a parameter, all the elements of the list are copied. If it is a reference to a list, only the address of the list is copied. What’s your say about those statements?
My answer was “If it is a reference to a list, not only the address is copied but also the value” and I got 5 out of 10 point.
Did I my answer wrong? For me, that’s what I got. Does the statement above correct?
If you pass by reference, a copy of the object is not made. That’s the difference between passing by reference and passing by value.
Under the hood, references are implemented as pointers, so you can say the address is copied, but that’s an implementation detail.
The formulation though is wrong:
It doesn’t matter if you pass a list or a reference to a list. What matters is how the method takes parameters – either by value or by reference: