void swap(int* &x, int* &y) //reference to pointer to int
{
int t=*x;
*x=*y;
*y=t;
}
int main()
{
int x=10, y=20;
cout<<x<<" "<<y<<endl;
swap(x,y); //No compilation error showed even though the
//args are of type int instead of int*
cout<<x<<" "<<y<<endl;
}
The swap function takes references to pointers to integers. But I saw that it can even take args of type int and swap them. How is it possible?
Output: 10 20
20 10