How to write a C++ Program to swap two numbers using function and pointers in C++ programming ?
C++ Program to swap two numbers using function and pointers in C++ programming |
Solution:
//Program to swap two numbers using function and pointers.
#include<iostream.h>
#include<conio.h>
void swap(int*,int*);
void main()
{
clrscr();
int a,b,c;
cout<<"Enter one numbers: ";
cin>>a;
cout<<"Enter second number: ";
cin>>b;
swap(&a,&b);
cout<<a<<" "<<b;
getch();
}
void swap(int *a,int *b)
{
int *c;
*c=*a;
*a=*b;
*b=*c;
}
This C++ Program to swap two numbers using function and pointers in C++ programming.