Â
The Code given below can be used in TURBO C++ Compilers: -
#include <iostream.h>
#include <conio.h>
#include <math.h>
void swap(int *p,int *q)
{
int temp;
temp=*p;
*p=*q;
*q=temp;
cout<<"\nAfter Swap\n";
cout<<"p="<<*p<<"\tq="<<*q<<endl;
}
void main()
{
int *p = new int(10);
int *q = new int(15);
cout<<"Before Swap\n";
cout<<"p="<<*p<<"\tq="<<*q<<endl;
swap(p,q);
delete p,q;
getch();
clrscr();
}
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
#include <math.h>
using namespace std;
void swap(int *p,int *q)
{
int temp;
temp=*p;
*p=*q;
*q=temp;
cout<<"\nAfter Swap\n";
cout<<"p="<<*p<<"\tq="<<*q<<endl;
}
int main()
{
int *p = new int(10);
int *q = new int(15);
cout<<"Before Swap\n";
cout<<"p="<<*p<<"\tq="<<*q<<endl;
swap(p,q);
delete p,q;
return 0;
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP