LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   parameter passing mechanisms (http://www.linuxquestions.org/questions/programming-9/parameter-passing-mechanisms-88071/)

dhanakom 09-01-2003 03:26 PM

parameter passing mechanisms
 
Hi,

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.

Thanks

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.

Alex

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 is...no 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 01:01 AM.