Swapping Values Using Pointer

2 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:




2 comments:

nice post stating is good.


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

10 March 2020 at 23:58 comment-delete

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.

27 April 2026 at 03:08 comment-delete
Post a Comment

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