Question: Consider the following code written in C syntax: void swap ( int a , int b ) { int temp; temp = a; a =

Consider the following code written in C syntax:
void swap(int a, int b){
int temp;
temp = a;
a = b;
b = temp;
}
void main(void){
int v =2, list[5]={1,3,5,7,9};
swap(v, list[0]);
int v =2, list[5]={1,3,5,7,9};
swap(list[0], list[1]);
int v =2, list[5]={1,3,5,7,9};
swap(v, list[v]);
int v =2, list[5]={1,3,5,7,9};
swap(list[v], v);
}
For each of the following parameter passing methods, show the values of v and of all the elements of list after each call to swap(). Show the value of v first, followed by the values in the array in order, or, if there is an error, indicate the error.
Please note that v and list are reset to their initial values before each call to swap().
A) Pass-by-value
B) Pass-by-reference
C) Pass-by-value-result
D) Pass-by-name

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!