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:


2 comments:
nice post stating is good.
https://www.kellytechno.com/Hyderabad/Course/AI-Training-In-Hyderabad
Great article! Very helpful for readers looking for clear insights. For those interested in skill development, check out best training institute in Chennai offering quality courses. Helpful information about best guest posting sites.
Post a Comment