-   Programming (
-   -   parameter passing mechanisms (

dhanakom 09-01-2003 03:26 PM

parameter passing mechanisms

can someone tell me why and when one of the following is prefered over the other

pass by reference using reference arguments

pass by reference using pointer arguments

Both are insecure (unless const is used to qualify the parameters)
but dont both of them essentially have the same dynamics ?? so why is one prefered over the other ??

Please eluciate.


llama_meme 09-01-2003 03:45 PM

You can't do pointer arithmetic on references. For example, if I pass a function a pointer to a single character, there's nothing to stop that function treating the argument as an array of characters. This couldn't happen if the function required a reference to a character instead of a pointer to a character.


jinksys 09-01-2003 05:15 PM

I agree with the previous post.

Pros with passing References:
When passing a reference, the code inside of the function treats the reference just like a global variable - that need to use * operators and changes to the reference changes the passed variable.

Cons with passing References:
References are not pointers and cannot be manipulated
via pointer arithmatic.

All times are GMT -5. The time now is 06:37 AM.