This is the code to swap 2 numbers and it works fine. But I'm curious about the "&" in front of x1 and x2 in the swap function. My code couldn't work before I added that two. What does that "&" do?
#include<iostream>
using namespace std;
void swap(int &x1,int &x2){
int x = x1;
x1 = x2;
x2 = x;
}
int main(){
int n1 , n2;
cin >> n1 >> n2;
swap(n1,n2);
cout<<n1<<" "<<n2;
return 0;
}