Question
Must be done in C++, please, and thank you. Comments that help in explaining are appreciated! Write a void function called swap that swaps two
Must be done in C++, please, and thank you. Comments that help in explaining are appreciated!
Write a void function called swap that swaps two int variables passed to it, must use pointers and use references. Please test the functions using the main function code that I have provided without changing it. Thanks again!
#include
int main()
{
cout << "The- Question:" << endl;
int num1 = 12; int num2 = 51;
cout << "Before using the pointer swap function " << "num1 = " << num1 << ", " << "num2 = " << num2 << endl; swap(&num1, &num2); cout << "After using the pointer swap function " << "num1 = " << num1 << ", " << "num2 = " << num2 << ". " << endl;
cout << "Before using the reference swap function " << "num1 = " << num1 << ", " << "num2 = " << num2 << endl; swap(num1, num2); cout << "After using the reference swap function " << "num1 = " << num1 << ", " << "num2 = " << num2 << ". " << endl;
}
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