Silly question... but how do I know if f2 works on a copy of a? And what about f1? Does having a in the brackets of f1 and f2, means they work on a copy of a?
If variable, (say "a" in this case) is defined in-scope it is local to that function.
1 2 3 4 5 6
void foo(int a)
{
// variable a is only handled in this function and does not affect calling inputs
}
//Somewhere else in code
foo(variable); // Does something but do not effect "variable" in calling function
Simple way to change behavior so function effects passed arguments is to add &-symbol:
1 2 3 4 5 6 7 8 9 10
void foo(int &a)
{
// lets say:
a=1234;
//now variable used in call has changed
}
//.... now calling from somewhere else:
foo(some_variable_to_change); // does in fact change variable
//..