Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

6. Some languages, notably Algol, uses pass-by-name parameter passing mechanism.

ID: 3669948 • Letter: 6

Question

6. Some languages, notably Algol, uses pass-by-name parameter passing mechanism. Consider the following C program:

int i;

int a[3];

void swap(int x, int y) {

x = x + y ;

y = x - y ;

x = x - y ;

}

main() {

i = 1 ;

a[0] = 2 ;

a[1] = 1 ;

a[2] = 0 ;

swap(i, a[i]) ;

printf("%d %d %d %d ", i, a[0], a[1], a[2]);

swap(a[i], a[i]) ;

printf("%d %d %d ", a[0], a[1], a[2]); return 0;

}

What does this program print if the paramter passing mechanism is:

(a) Pass by value,
(b) Pass by value-result,
(c) Pass by reference, and
(d) Pass by name.

Explanation / Answer

a) Pass By Value

1 2 1 0
2 1 0

b) Pass by value-result

1 2 1 0
2 1 0

c).

1 2 1 0
2 0 0

d).

1 2 1 0
2 0 0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote