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);
}
- 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
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
Get step-by-step solutions from verified subject matter experts
