#include <iostream>
using namespace std;
void swap(int *x, int *y) //getting the pointers
{
int temp;
temp = *x;
*x=*y;
*y = temp;
}
int main()
{
int a, b;
a=10;
b=20;
swap(&a,&b); //passing the address
cout << "a = "<<a <<", b = "<<b << endl; //a = 10, b = 20
return 0;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter