Implement the body of the swap function using the indirection operator // finish this program so that the values of // x and y are swapped in main(). #include <iostream> using namespace std; void swap(int* first, int* second) { // IMPLEMENT THIS FUNCTION // YOUR CODE GOES HERE } int main() { int x = 9; int y = 2; swap(&x, &y); cout << "x: " << x << endl; cout << "y: " << y << endl; // if your program works, it will print: // x: 2 // y: 9 }
Given below is the completed code for the question. Please do rate
the answer if it helped. Thank you.
// finish this program so that the values of
// x and y are swapped in main().
#include <iostream>
using namespace std;
void swap(int* first, int* second)
{
int temp = *first;
*first = *second;
*second = temp;
}
int main()
{
int x = 9;
int y = 2;
swap(&x, &y);
cout << "x: " << x << endl;
cout << "y: " << y << endl;
// if your program works, it will print:
// x: 2
// y: 9
}
Get Answers For Free
Most questions answered within 1 hours.