Question: In general, when is it better to use call-by-value over call-by-reference for a function argument? Give an example of a programming scenario (aka a function)
-
In general, when is it better to use call-by-value over call-by-reference for a function argument? Give an example of a programming scenario (aka a function) where is certainly better to use call-by-value for one of the parameters.
-
Now the opposite question: in general, when is it better to use call-by-reference over call-by-value for a function argument? Give an example of a programming scenario (aka a function) where it is certainly better to use a call-by-reference parameter.
-
Consider the following programming scenario:
int i = -4, j = 10;
int *ptr1 = & i;
int *ptr2 = & j;
int &ref1 = i;
int &ref2 = j;
*ptr2 = *ptr1;
cout << *ptr2 << endl;
ptr2 = ptr1;
cout << *ptr2 << endl;
ref2 = ref1;
cout << ref2 << endl;
Circle all the instruction(s) that change the value of variable j after being initialized.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
