Implementation of swap function - void swap (int&a, int&b) int temp;

Q.  Which is the implementation of the swap function?

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);
}


2.

void swap (int&a, int&b) {
int temp;
temp = a;
a = b;
b = temp;
}
int main () {
int i = 0, j = 1;
swap (i, j);
}

3.

void swap (int *a, int *b)
{
int *temp;
temp = a;
a = b;
b = temp;
}
int main () {
int i = 0, j = 1;
swap (&i, &j);
}

- Published on 17 Jun 15

a. 3 Only
b. 2 Only
c. 2 and 3 only
d. None of the above.

ANSWER: 2 Only

Post your comment / Share knowledge


Enter the code shown above:
 
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)