Question: Why does this version of the swap function fail to work? Is there a fix? ( Choose 2 ) void swap ( int & lhs
Why does this version of the swap function fail to work? Is there a fix? Choose
void swapint & lhs int& rhs
lhs rhs;
rhs lhs;
Group of answer choices
It fails OK and we can fix it we can just reverse the order of the lines.
a To fix this, we must save the lhs value in a local variable before making the first assignment indicated, then instead of the second line, assign the rhs the value of the local variable:
int local lhs;
lhs rhs;
rhs local;
It fails because the first line destroys the old value of lhs without saving it Then both variables have the old value of rhs in them.
It fails because the programmer forgot to make the parameters callbyreference.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
