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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.