The C++ code defines a function called "exchange" that swaps the values of two integer variables passed as references. It is missing the expression in the function definition for the variable types. The missing expression is "int &a, int &b" which defines the parameters as integer references allowing the function to swap the actual variable values rather than copies.
c++ QUESTION 10 #include -iostream- using namespace std- void exchange.docx
1. c++
QUESTION 10
#include <iostream>
using namespace std;
void exchange(/* MISSING EXPRESSION*/)
{ int var(a); a=b; b=var;}
int main()
{
int i(10);
int j(55);
cout << "Before : i = " << i << " and j = " << j << endl; exchange(i,j);
cout << "Now : i = " << i << " and j = " << j << endl;
return 0;
}
Find the missing expression and upload your updated file.
the missing expression is the only part to modify before, testing the code then you submit your
updated code.
Solution
main.cpp
2. #include <iostream>
using namespace std;
void exchange(int &a, int &b)
{ int var=a; a=b; b=var;}
int main()
{
int i=10;
int j=55;
cout << "Before : i = " << i << " and j = " << j << endl;
exchange(i,j);
cout << "Now :Â Â Â i = " << i << " and j = " << j << endl;
return 0;
}
Output :