Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started