So I am trying to understand a simple piece of code that 'emulates' Pass-by-reference using pointers in a Pass by value function. The example is given as a C practice since there is no Pass by reference in C. but I am also curious about its effects on C++.
so after running this code the values are swapped:
void swap(int* a, int* b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
I am trying to understand why passing pointers as arguments create a pass-by-reference effect? Does it mean all actions that are performed through pointers have a pass-by-reference effect? So the swapped memory location will not go back once we quit the function? Would this also be valid in C++?
New to coding so I hope I could make myself clear.