Question: 4. (9.5) Modify the program in Figure 9.1 so that the function B has no side effects on the global variable i. Instead, B should

 4. (9.5) Modify the program in Figure 9.1 so that the

4. (9.5) Modify the program in Figure 9.1 so that the function B has no side effects on the global variable i. Instead, B should return an int value, which is the calculation 2*w. Also, the call to B from A should be modified so that this result is assigned to the global variable i. The local variable declaration of i within A should be removed. Run this modified program using your favorite C++ compiler and answer the following questions: (a)Describe the activation record that occurs when this call is interpreted (b) This modified program has the same global effect as the original program in Figure 9.1. What would have happened if you had not removed the declaration of the local variable i from A? program from Figure 9.1 int h, i; void B(int w) ( int j, k; w w+1 ; = void A(int x, int y) ( int i, j; B(h); int main() int a,b; h=5; a=3, A(a,b); b=2

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!