All rights are reserved by Niteesh Kumar.. Theme images by Storman. Powered by Blogger.

Followers

Total Pageviews

Blog Archive

Follow by Email

Translate

Monday, 5 May 2014

c++ program to swap two numbers using pointers


Here a and b are two no. and we are swapping them.It means we are interchanging the values of  a and b.
//
#include<iostream.h>
#include<conio.h>

void main()
{clrscr();
int *a,*b,*c,p,q;
cout<<"enter 2 nos.=";
cin>>p>>q;
a=&p;
b=&q;
*c=*a;
*a=*b;
*b=*c;
cout<<"swapping nos.="<<*a<<'\n'<<*c<<'\n';
getch();
}

OUTPUT
enter 2 nos.=7
5
swapping nos.=5

7

0 on: "c++ program to swap two numbers using pointers"