02 Jul PROGRAMMING ORG. LANGUAGE
Programming Org. Language
1. Consider the following program written in C syntax:
void fun (int first, int second) {
first += second;
second += first;
}
void main () {
int list[2] = {6, 7};
fun (list[0], List [1]);
}
For each of following parameter-passing methods, what are the values of the list array after execution?
a. Passed by value
b. Passed by reference
c. Passed by value-result
2. Consider the following program written in C syntax:
#include <iostream>
typedef float(*pFooType)(float, float);
float A(float num1, float num2) {return num1 + num2;}
float B(float num1, float num2) {return num1 num2;}
float C(float num1, float num2) {return num1 * num2;}
float D(float num1, float num2) {return num1 / num2;}
float Calc(float num1, float num2, float (*pCalcMethod)(float,
float))
{
return pCalcMethod(num1, num2);
}
int main()
{
pFooType pFoo[] = ;
float result;
for(int i = 0; i < 4; ++i)
{
result = Calc(10, 2, pFoo[i]);
std::cout << result << , ;
}
return 0;
}
Fill out the blank in order to generate the output — 8, 12, 5, 20,
3. Show the stack with all activation record instances, including static and dynamic chains, when execution reaches position 1 in the following skeletal program. Assume Bigsub is at level 1.
procedure Bigsub is
MySum : Float;
procedure A is
X : Integer;
procedure B(Temp : Float) is
Y, Z : Float;
begin — of B
. . .
C(Z);
. . .
end; — of B
begin — of A
. . .
B(X);
. . .
end; — of A
procedure C(Plum1 : Float) is
begin — of C
. . . position 1
end; — of C
L : Float;
begin — of Bigsub
. . .
A;
. . .
end; — of Bigsub
Note that, B is nested in A
4. The following producer-consumer programs written in C.
Void producer(void){
int item;
while (TRUE) {
produce item(&item);
produce_item(&item);
if (count == N) sleep();
enter_item(item);
count = count + 1;
if (count == 1)
wakeup(consumer);
}
}
Suppose that the programs share items and work concurrently. This can result in both processes (producer and consumer) going to sleep. Explain what it is.
5. Consider the following program written in a pseudo-code.
int x = 10;
void a(){
x = x + x;
}
void b(){
c(a);
}
void c(d){
int x = 20;
d();
}
b();
print(x);
a) Suppose this program uses static scoping. What is the output of the program? Explain why?
b) Suppose this program uses dynamic scoping with deep binding. What is the output of the program? Explain why?
c) Suppose this program uses dynamic scoping with shallow binding. What is the output of the program? Explain why?
6. To reclaim garbage for heap management, there are two approaches: reference counters and mark-sweep. The mark-sweep garbage collection occurs more frequently than reference counters before memory is exhausted, resulting in more effective garbage collection. Explain the side-effect of mark-sweep
Note that, the question is the side-effect but not disadvantage.
7. The following program is written on the form of a selection guarded command
if i = 1 -> sum := sum + i
[ ] i > j -> sum := sum + j
[ ] j > i -> sum := sum + j
fi
print sum
a) Suppose the initial values: sum=0, i=1 and j=2. What is the output of this program?
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Writedemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.
