In this program, You will learn C++ Program to Swap Two Numbers using Pointers.pointers as an argument to the function, and use it efficiently in your program.
C++ Program to Swap Two Numbers using Pointers
#include<iostream>
using namespace std;
int main() {
int x, y, temp;
int *a, *b;
cout << "Enter two Numbers :";
cin >> x>>y;
a = &x;
b = &y;
temp = *a;
*a = *b;
*b = temp;
cout << "\nAfter Swap x is :" << x;
cout << "\nAfter Swap y is :" << y;
return 0;
}
Output of Program
Enter two Numbers :2
45
After Swap x is :45
After Swap y is :2