Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

One important question about by-result parameter passing that was not mentioned

ID: 3821708 • Letter: O

Question

One important question about by-result parameter passing that was not mentioned is this: when does the language system compute the Ivalue of the actual parameter? (The Ivalue of the actual parameter is the memory location to which the final value of the formal parameter is written.) You might have assumed that this would be computed, like a by-reference parameter, before the called method executes. But since it is not needed until the called method returns, its computationcould be delayed until it is needed, like a by-name parameter. Ada does it the early way, while Algol W does it at the last minute.

Here is an example that illustrates the difference:

void f(int [ ] A) {

int i = 0;

g (i, A [i]);

}

void g (by-reference int i, by-result int j) {

j = 2;

i = 1;

j = 3;

}

For each of these two different interpretations of by-result parameter passing, explain what happens when f calls g. In particular, say exactly what happens when any change is made to i or A

Consider the following Java like code fragment: int[]A* 12, 3); Where f is defined as follows: void f (int x int y, int z) int temp tempi For each of the given parameter passing methods, what are the values of j, k, AC01, and AC1] upon return from f? Fill in the table. ax y and z are passed value b.x y and z are passed by reference. 20 3 C) x y and z are passed by value-result d) x is passed by value and y and z are passed by reference 210 3 e) x, y and zare passed by name

Explanation / Answer

for a) part upon returning from f the original values definrd for j,k a[0] will pertain because the funtion f exchange the values locally inside the block only and the values will not reflect globally

for b) when the values are passed by reference means that actually the fuction is implementing the addresses of these values for swapping the data not locally but globally so it is changed and reflected globally

c)when pass by value rsult it also showing the change in the values because the final result is reflected globally foe all the variablea and then pass it to the function hence the resultant values pertain

d)as shown in the image x is passed by value hence its value didn't changed but but y and z are passed by reference so their value reflected globally as discussed in b part

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote