There are basically three types of parameters; pointer, referential and direct.
The difference is quite simple: direct parameters are transmitted by value, and the recipient receives a copy of the transmitted; that if the parameter is changed by the recipient, these changes will not be returned back to the caller. (This is often called appropriately, passed by value or bycopy .
Pointers are also passed by value, but instead of sending the actual value, the caller sends the address of the value. This means that by following this pointer, the receiver can change the argument. Note that changes made to the actual index are still not reflected back to the caller.
The final form invoked by reference is a kind of intermediate point between the two approaches. Essentially, this can be thought of as a pointer that looks like a value.
It should be noted that at the heart of all this, parameters are always passed by value, but different languages have different ways of implementing reference semantics (see Kylotans answer).
// Example using C // bycopy int multiply(int x, int y) { return x * y; } void multiply_p(int *x, int y) { *x *= y; } int main () { int i, j, k; i = 20; j = 10; k = multiply(i,j); // k is now 200 multiply_p(&i, k); // i is now 4000 (200 * 20) return 0; }
Williham Totland
source share