Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The subroutine pass_by_val must use a pass-by-value parameter passing mechanism to pass all parameters. The subroutine pass_by_ref must use a pass-by-value parameter passing mechanism for

The subroutine pass_by_val must use a pass-by-value parameter passing mechanism to pass all

parameters. The subroutine pass_by_ref must use a pass-by-value parameter passing mechanism for

the primitive types and pass-by-reference for the array.

You must create activation records on the stack for each subroutine (including main) and utilize the

frame pointer and stack pointer in an appropriate manner. Your activation records will store the

previous frame pointer, local variables, and parameters. You can use a dummy value for the initial frame

pointer.

void main( ) {

// Note that size and myArray are local variables inside of main

int size = 10;

int myArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

// print myArray

pass_by_val(size, myArray, 2);

// print myArray

pass_by_ref(size, myArray, 5);

// print myArray

}

// pass_by_val must use pass-by-value mechanism for all parameters.

// Note that we use a lot of space when an array is passed by value.

void pass_by_val(int size, int a[], int n) {

// note that i is a local variable in the pass_by_val function

int i;

for (i=0; i

a[i] = a[i] * n; // multiply each element by n

}

// pass_by_reference must use pass_by_reference for the array

// array parameter and pass-by-value for all other parameters

void pass_by_val(int size, int a[], int n) {

// Note that i is a local variable in the pass_by_ref function

int i;

for (i=0; i

a[i] = a[i] + n; // add n to each element

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

8 8 . .

Answered: 1 week ago