Question: CS 3 0 0 3 : Comparative Programming Languages Fall 2 0 2 4 Wainwright Homework Set 4 2 5 points Due: Friday November 2

CS 3003: Comparative Programming Languages Fall 2024
Wainwright Homework Set 425 points
Due: Friday November 22,2024 at class time.
In each case YOU MUST SHOW ALL OF YOUR WORK and work independently.
1. Consider the following code:
program MAIN;
var i : integer;
var a : array[1..5] of integer;
procedure SUB(x : integer);
{x++; a[i] := a[i-2]+3; i++; x++; a[i] := a[i+1]+ x; x++; i++; a[i] := a[i]+ x;}
(end SUBPROG)
{a[1] :=2; a[2] :=3; a[3] :=4; a[4] :=5; a[5] :=6; i :=3;
call SUB(a[i]);
print (a[1..5]);
}
(end MAIN)
Note: Assume that all un-initialized variables have the value zero.
Note: For each question below (a) through (f) work must accompany your solution.
Show in detail the trace you used to arrive at each of the answers.
(4 pts)
(a) What is the program output assuming that the parameter is passed by value?
(4 pts)
(b) What is the program output assuming that the parameter is passed by result?
Assume that the address of the pass by result parameter is bound at the time of call.
Also assume the initial value for x is zero.

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 Programming Questions!