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)

  1. 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.

  2. 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.

  3. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!