So I have this
#include <iostream>
using namespace std;
void swap(int *x, int *y) {
int temp = *x;
*x = *y;
*y = temp;
}
int main() {
int a = 4;
int b = 3;
swap(a, b);
cout << a << endl << b;
}
What I don't understand is why this works, in all the examples of this I see online they use references ie &a and &b, which makes sense but this somehow works too, why?