Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-01-2003, 02:26 PM   #1
LQ Newbie
Registered: Jul 2003
Location: Birmingham
Posts: 20

Rep: Reputation: 0
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.

Old 09-01-2003, 02:45 PM   #2
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
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.

Old 09-01-2003, 04:15 PM   #3
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 419

Rep: Reputation: 35
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
setting up scp alias under bash - parameter passing problem gjr Linux - Newbie 4 06-08-2005 06:38 AM
Passing hash of hashes as a parameter (Perl) rose_bud4201 Programming 8 04-21-2005 07:18 PM
Passing one php function result as a parameter to another php function davee Programming 13 09-12-2004 12:08 PM
IPC Mechanisms ananthbv Programming 5 12-20-2003 11:57 AM
Passing parameter to kernel when booting from floppy NewtoSlack Slackware 1 10-10-2003 08:24 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:56 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration