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 15a. 3 Only
b. 2 Only
c. 2 and 3 only
d. None of the above.
ANSWER: 2 Only