logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

What is the output of the program for each of the parameter-passing methods below:

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

1. In the C program below:

 

void main() {

int element = 0, arr[6] = {1,4,6,2,0,3};

 

sub1(element,arr[0]);

printf("%d and [%d,%d,%d,%d,%d]\n",

element,arr[0],arr[1],arr[2], arr[3],arr[4]);

 

sub1(arr[0],arr[2]);

printf("%d and [%d,%d,%d,%d,%d]\n",

element,arr[0],arr[1],arr[2], arr[3], arr[4]);

 

sub1(element,arr[element]); printf("%d and [%d,%d,%d,%d,%d]\n",

element,arr[0],arr[1],arr[2],arr[3],arr[4]);

 

return 0;

}

 

void sub1(int a, int b) {

int temp; temp = a; a = b;

b = temp;

b=a+b;

}

What is the output of the program for each of the parameter-passing methods below:

 

a) Passed by value

b) Passed by reference

d) Passed by value-result

 

2. In the program segment in C below, address() prints the address of the function fun.

 

void fun () {

printf("\n Hello world!");

}

void address() { printf(“address: %u", fun);

}

 

a) Re-write address()to take in any function and print its address (i.e., parametrize it). Hint, in C you can pass functions as parameters using pointers. Save this program containing the re- written function address() as findAddress.c.

 

c) Re-write the Javascript program on the right to C.

Run sub1 using a call in a main program; what is the result? (you can change alert() to printf()). Based on this result, discuss whether or not

C uses deep binding, shallow binding,

or ad-hoc binding for reference environments of subprograms passed as parameters.

 

Save your main program as test.c

 

 

 

 

3. For the skeletal JavaScript program in the next page (remember that the choice of programming language I make is often arbitrary and doesn’t affect the solution) – perform the following:

 

a) What is the call sequence for the program assuming bigsub() is run from some main program, main()? This question is a lovely example that we came up with in class together of how recursion – in this case it’s indirect recursion – can be performed using parametrization. Note: Boolean() is a function in Java that outputs false if its parameter is 0, and true otherwise.

 

b) Show how the stack looks like for all the subprograms given the call sequence for a), which will include all activation record instances, including static and dynamic chains, when execution reaches position 1. Assume the subprogram bigsub has nest_depth of 0. Also assume the order of declaration and stack pushes of variables is left-to-right (e.g., in var y,w; y is pushed first then w is pushed next onto the stack).

 

c) For each variable in the expression at position 1, show their chain offset and local offset.

 

d) Show the table for reference variables at position 1 assuming dynamic scope and a shallow access implementation. (this is like the table I showed in the second last slide of Week 10).

 

 

 

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

727 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

796 Answers

Hire Me
expert
Husnain SaeedComputer science

717 Answers

Hire Me
expert
Atharva PatilComputer science

741 Answers

Hire Me