That's a completely inaccurate statement.
In C, passing an integer variable by value results in the same integer value being assigned to the argument.
Passing an array in Perl by value does not any more end up with the same "array value" inside the sub than passing a bare, anonymous list ends up with the same "list value" inside the sub. In fact, the bare, anonymous list is more likely to be preserved in its entire identity (only because it has less identity to lose) than the array is. All that gets passed are multiple scalars in order.
When passing a pointer to a variable in C, you are not passing anything by reference at all. You are passing a pointer by value, and must use the pointer inside the function as a pointer and not as the variable. This is the same as taking a reference to a variable in Perl and passing that in. The technique of using the prototype feature to force the taking of the reference is syntactic sugar.
An aside... K&R call passing a pointer into a function "pass by pointer", because it is pass-by-value but buys you some of the benefits of pass-by-reference when you really need them. The possibility of using pointers is part of what convinced Dennis M. Ritchie that C should be pass-by-value, because with them pass-by-reference's additional caveats are only necessary when you choose to emulate pass-by-reference and not the rest of the time.
If you really want to see what pass-by-reference is, take a look at the pseudocode below.
foo = 1;
bar = 5;
function inc_dec( x, y ) {
x++;
y--;
return( x, y );
}
res1, res2 = inc_dec( foo, bar );
If this was a pass-by-value language, foo would be 1, bar would be 5, res1 would be 2, and res2 would be 4. If it was pass-by-reference, res1 would still be 2 and res2 would still be 4. Yet with pass-by-reference our imaginary language here would produce foo with a value of 2 and bar would have a value of 4. No dereferencing within the function is necessary. That's pass-by-reference.
Update: s/bar have a value/bar would have a value/ |