Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #define ARRAY_LENGTH 5 using namespace std;

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions