I think that this is a very trivial discussion going on abt passing variables. I'm sure that passing by address (or reference) can be checked out in any C book.
Passing by reference is a Algol 68/C++ concept. It does not exist in C. Algol 68 brought out passing by reference because PL/1 gave pointers a bad name. Then they found that they could do some useful things with it, like returning the results of operators.
The nearest you can get to it in C is to use a pointer. Basically
Passing by location came from FORTRAN in the fifties. There is call by name, reference, location and value. We still use location in C but you pass a pointer to the location by value. It is the same in Coral 66.
This flaw was quite common in the early fortran compilers. You could define a routine
subroutine fred(x)
x = 50
return
end
To use it,
y = 10
call fred (0)
y = y + 0
write (5, 'F10.1') y
And you would get 60. Nowadays, you'd probably get 'attempt to write to null pointer'.
It's a really important concept though, and worth differentiating in a more meaningful way than pedantics about whether a pointer is itself just a value. Can you imagine the consequences of passing a large array by value? Also, things passed by value cannot be changed by the function they're passed to. Things passed by address can.
Things passed by value can be changed by the function they're being passed into: the only difference is that the caller doesn't see the modified result because the called function uses a copy and not the original. That's the new thing about using const. You could read it as 'I promise not to change this' but then again you could always cast away the constness.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.