The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 6 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
#include <iostream>
#include <string>
Â
using namespace std;
Â
void swap(int a, int b)
{
     int temp = a;
     cout<<"a and b have the following values at the start of swap"<<endl;
     cout<<"a = "<<a<<" and b = "<<b<<endl;
     a=b;
     b=temp;
     cout<<"a and b have the following values at the end of swap"<<endl;
     cout<<"a = "<<a<<" and b = "<<b<<endl;
Â
}
int main()
{
     int a=111, b=222;
Â
     cout<<"a and b have the following values before swap is called"<<endl;
     cout<<"a = "<<a<<" and b = "<<b<<endl;
     swap(a,b);
     cout<<"a and b have the following values after swap is called"<<endl;
     cout<<"a = "<<a<<" and b = "<<b<<endl;
     return 0;
}
Â
Question 1:Are the variables a and b used in the function main the same a and b variables that are used in the function swap in the program in Step 1? Explain your answer.
Question 2:Were the values stored in the variables a and b in the function main swapped after the execution of the function swap in the program in Step 1? Explain your observations.
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll