Question: Write in C++ Using C++, write a function that can swap the values of two variables. Use reference semantics so that the original variables that

Write in C++

Using C++, write a function that can swap the values of two variables. Use reference semantics so that the original variables that are passed into the function are swapped.

Starter Code:

#include  #include  #include  #include  int main() { int i = 5; int j = 7; std::cout << "i = " << i << " "; std::cout << "j = " << j << " "; // TODO: write and call a function capable of swapping the values of 'i' and 'j' in-place. Implement the swap within the function itself, the only code you should add to main is the function call to your new swap function. i.e. swap(i, j); std::cout << "i = " << i << " "; std::cout << "j = " << j << " "; } 

Sample Output:

i = 5 j = 7 i = 7 j = 5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!