Lets say I have
void swap(int &x, int &y){
//do swap here
}
Why is it legal to do: x = y
inside of the function so that it assigns the VALUE of y
to x
?
Why isn't some sort of dereferencing needed?
Lets say I have
void swap(int &x, int &y){
//do swap here
}
Why is it legal to do: x = y
inside of the function so that it assigns the VALUE of y
to x
?
Why isn't some sort of dereferencing needed?
There's no dereferencing needed since references are not pointers. They are aliases to the referenced object.