Swapping Values Using Pointer

1 comments
Here is the code You can use to swap values of two variables using Pointer Method




#include<iostream.h>
#include<conio.h>

void main()
{clrscr();
int x,y;
int *p1,*p2,*p3;
cout<<"ENTERS THE VALUES FOR x= ";
cin>>x;
cout<<"\nENTERS THE VALUES FOR y= ";
cin>>y;
p1=&x;
p2=&y;

p3=p1;
p1=p2;
p2=p3;

cout<<"THE VALUES AFTER SWAPPING ARE \nx= "<<*p1<<"\ny= "<<*p2;

getch();

}

Output:




1 comments:

nice post stating is good.


https://www.kellytechno.com/Hyderabad/Course/AI-Training-In-Hyderabad

10 March 2020 at 23:58 comment-delete
Post a Comment

Copyright 2011 Programming In C++.
Blogger Template by lordhtml / Free Blogger Template