pointer to function swap two number
#include<bits/stdc++.h>
using namespace std;
void swp(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
int main()
{
int n1=10,n2=20;
cout<<n1<<" "<<n2<<endl;
swp(&n1,&n2);
cout<<n1<<" "<<n2<<endl;
return 0;
}
pointer to function swap two number
#include<bits/stdc++.h>
using namespace std;
void swp(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
int main()
{
int n1=10,n2=20;
cout<<n1<<" "<<n2<<endl;
swp(&n1,&n2);
cout<<n1<<" "<<n2<<endl;
return 0;
}
0 Comments