cs509:cpluscplusswapbyvalue
See the following code:
#include <iostream>
using namespace std;
void swapvars( int a, int b ) {
int temp = a;
a = b; // a is now b
b = temp; // b is now a
}
int main ()
{
int a = 2;
int b = 3;
swapvars( a, b );
cout << "The value of a is " << a << " and the value of b is " << b;
return 0;
}
What will be output by the above program?
- a - The value of a is 2 and the value of b is 3;
- b - The value of a is 3 and the value of b is 2;
- c - The value of a is 2 and the value of b is 2;
- d - The value of a is 3 and the value of b is 3;
<poll What will be output by the above program? [c]>
- a
- b
- c
- d
</poll>
cs509/cpluscplusswapbyvalue.txt · Last modified: by jchung
