why cannot assign to function call
joe at strout.net
Sat Jan 10 20:52:47 CET 2009
rurpy at yahoo.com wrote:
> What is the observable difference between converting an
> array to a reference (pointer) to that array and passing
> the reference by value, and passing the array by reference?
The difference is whether an assignment to the formal parameter (within
the function) affects the actual parameter (in the calling code). If it
does, then that's pass by reference. If it does not, then that's pass
> That is, given a C-like compiler that is the same as
> C except that it passes arrays by reference, how would
> it differ from an ordinary C compiler?
Such a compiler is available: it's called C++, and it gives the
programmer the choice to pass by value or pass by reference (the latter
indicated by adding "&" to the parameter in the function declaration,
just like you would add "ByRef" in RB or VB.NET).
If the parameter is called "foo", and you pass in "bar", then
foo = SomeNewArray();
would change bar if it were passed by reference; it would not affect bar
at all if it were passed by value.
The two are quite distinct.
More information about the Python-list