C++ program to exchange values of two variables (Swapping) using pointer. This program uses a function called exchange(int*,int*) that takes two argument as integer pointers. The variables are passed by reference method and hence, the swapping done at the exchange function will reflect in the main method also.
#include<iostream>
#include<conio.h>
using namespace std;
void exchange(int*, int*);
void main()
{
int x,y;
cout<<“Enter x :”;
cin>>x;
cout<<“nEnter y:”;
cin>>y;
cout<<“Before Exchange : x = “<<x<<” y = “<<y<<“nn”;
exchange(&x,&y); //Calling Exhcange function to swap
cout<<“After Exchange : x = “<<x<<” y = “<<y<<“nn”;
getch();
}
//No need to return any values since the variables are already affected.
void exchange(int *a, int *b)
{
int t;
t = *a; //Saving data in first variable to an intermediate one
*a = *b; //Saving second variable to first
*b = t; //Saving intermediate variable to second
}
[Compiled using Visual Studio]
… [Trackback]
[…] Find More Info here to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More on on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More on on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Find More on on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Information on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Find More Information here on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Find More on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More Information here on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More Info here on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Info on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Find More on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Find More on on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Info to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More here to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More here on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Information on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Find More here to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Here you will find 74538 more Info to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More here to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Find More on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More on to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Find More Information here to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Find More on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More on on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Find More on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More Information here on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More here on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Info on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] There you can find 55769 more Info on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Find More to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More here to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Info to that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Read More Information here on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]
… [Trackback]
[…] Here you can find 2514 additional Info on that Topic: genuinecoder.com/cpp-exchange-values-of-two-variables-swapping-html/ […]