C++ Program for Swapping of Numbers using Pointers

Program code:

#include<iostream>

using namespace std;
int main()
{
int x  , y , z , *a , *b , *c  ;
cout<<"Enter value of x : ";
cin>>x;
cout<<"Enter value of y : ";
cin>>y;
cout<<"Before swapping x :  "<<x;
cout<<"\nBefore swapping y :  "<<y;
a = &x;
    b = &y;
c = &z;
*c = *a;
*a = *b;
*b = *c;
cout<<"\nAfter swapping x :  "<<x;
cout<<"\nAfter swapping y :  "<<y;
return 0;
}

Output:

.exe file

No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.