Question: Given below are three implementations of the swap function: a. void swap (int a, int b) { int temp; temp = a; a = b;

Given below are three implementations of the swap function:

a. void swap (int a, int b)

{

int temp;

temp = a;

a = b;

b = temp;

}

int main ()

{

int i = 0,

j = 1;

swap (i, j);

}

b. void swap (int &a, int &b)

{

int temp;

temp = a;

a = b;

b = temp;

}

int main ( )

{

int i = 0,

j = 1;

swap (i, j);

}

  1. void swap (int *a, int *b)

{

int *temp;

temp = a;

a = b;

b = temp;

}

int main ( )

{

int i = 0,

j = 1;

swap (&i, &j);

}

Which of these would actually swap the contents of the two integers i and j ?

A. a only

B. b only

C. c only

D. a and b only 6.

E. b and c only

Step by Step Solution

3.39 Rating (155 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The detailed answer for the above question is provided below The correct answer is E b and c only Lets analyze each implementation a swapint a int b This function takes copies of a and b by value Swap... View full answer

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 Operating System Questions!