When pass a variable to a function, why the function only gets a copy/duplicate of the variable?
int n=1;
void foo(int i)
{
i++;
}
As
I guess one reason is efficiency, it's more efficient to access values directly then through a pointer. Another advantage is choice, the C/C++ way you can choose to pass arguments by value or by pointer, your way you only have the choice to pass by pointer. But most importantly passing by value means that your function is isolated from the rest of your code, and changes to variables inside the function don't affect the rest of the code. Believe me you would get far more bugs and coding would be more difficult if this were not the case.