Consider the following program in written in C/C++ syntax. // \"\\t\" leaves a f
ID: 667326 • Letter: C
Question
Consider the following program in written in C/C++ syntax.
// " " leaves a fixed amount of horizontal space
int j, k;
int a[3] ;
void swap(int x, int y) {
x = x + y;
y = x - y;
x = x - y;
}
int main() {
a[0] = 2;
a[1] = 1;
a[2] = 0;
j = 1;
swap( j, a[j] ) ;
for (k=0; k<3; k++)
cout << a[k] << “ ” ;
cout << endl;
swap( a[j], a[j] ) ;
for (k=0; k<3; k++)
cout << a[k] << “ ” ;
return 0;
}
For each of the following parameter passing methods, what do the cout statements from the main part of the program print. If you encounter aliasing, then let the variable modified last be used for the return value.
(a) Passed by value
(b) Passed by value-result
(c) Passed by reference
(d) Passed by name
Explanation / Answer
Hi,
Below are the solutions to your problem:
1.Passed by value:
Output: 2
1
0
2
1
0
2.Call by Value-result:
Output:2
0
1
2
0
1
Pass by reference:
output:
2
0
1
2
0
1
Hope that helps.HAPPY ANSWERING!!!!!!!!!!!!!!