Question: For the following code, show the output for the 5 output statements (#1..#5) under the parameter passing methods stated. Assume static scoping PROGRAM EX1; int

For the following code, show the output for the 5 output statements (#1..#5) under the parameter passing methods stated.

Assume static scoping

PROGRAM EX1;

int i; // global

int A[3]; // global {array starts at 1}

PROCEDURE P1 ( int x, int y)

BEGIN

y := 2;

i := 3;

PRINT(x, y) // #1 function prints the values of both x and y

END;

BEGIN //main

A[1]:= 7; A[2]:= 13; A[3]:= 11;

i := 1;

P1(A[i], i); // first call

PRINT(i) // #2

PRINT_A(A); // #3 assume function that prints the values found in the array A

P1(i, A[i]); // second call

PRINTT(i) // #4

PRINT_A(A); // #5 assume function that prints the values found in the array A

END.

a) x is passed by name and y is passed by reference.

#1__________ #2 ___________ #3 __________________ #4 ____________ #5____________________

#1__________ #2 ___________ #3 __________________ #4 ____________ #5____________________

b) x is passed by value-results and y is passed by reference.

#1__________ #2 ___________ #3 _________________ #4 ____________ #5____________________

#1__________ #2 ___________ #3 __________________ #4 ____________ #5____________________

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!