Why does this version of the swap function fail to work? Is there a fix?
```
void swap(int & lhs, int& rhs)
{
lhs = rhs;
rhs = lhs;
```
a) Of course it works! Just look at it. It clearly swaps the two parameters!
b) It fails because the programmer forgot to make the parameters call-by-reference.
c) It fails OK, and we can fix it we can just reverse the order of the lines.
d) 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.
e) 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:
d) 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.
e) 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
You might also like to view...
The _____________ manager is the simplest layout manager. It arranges components one after the other, going from left to right, in the order in which you add them.
(a) BorderLayout (b) FlowLayout (c) GridLayout (d) AbsoluteLayout
The test-and-set instruction ________.
a) prevents deadlock b) prevents indefinite postponement c) eliminates the possibility that a thread is preempted between reading a value from a memory location and writing a new value to the memory location d) none of the above
(Sorting strings) Write a version of the selection sort routine (Fig. 8.28) that sorts strings. Use function swap in your solution.
What will be an ideal response?
Which of the following is a method for creating macros?
A) Insert function button B) Formula builder C) Macro recorder D) Developer tools