Answer:
The program to this question can be given as:
Program:
#include <iostream>
//include header file (iostream).
using namespace std;
//using name space.
void swapints(int &j, int &k); // function declaration
void swapints(int &j, int &k) //function definition
{
int t; //define variable temp
//perform swapping
t = j;
j = k;
k = t;
}
int main () //define main method
{
int a = 15; //define variable.
int b = 23; //define variable.
cout <<"Before swapping"<<endl<<"value of a and b :"<<endl << a <<endl<<b;//print value.
swapints(a,b); //calling function.
cout <<endl<<"After swapping"<<endl<<"value of a and b :"<< endl << a <<endl<<b; //print value.
return 0;
}
Output:
Before swapping
value of a and b :
15
23
After swapping
value of a and b :
23
15
Explanation:
The description of the above program can be given as:
- In above C++ program firstly we include the header file that is "iostream". Then we define a method that is "swapints()". This method takes two integer parameter that is "j and k".
- swapints method is use to perform the swapping. In this method we define a variable that is "t" variable t holds the value of variable j and variable j holds variable k value and in the last variable k holds variable t value for this process all the value is swapped.
- In the main method, we define two integer variable that is "a and b" and assign the value "15 and 23" that is given in question and pass this variable into swapints() method and call it.