Link to home
Start Free TrialLog in
Avatar of mitchguy
mitchguy

asked on

using pointers vs reference parameters in functions

I'm a little unclear on what situations make it necessary to use one over the other when passing parameters in functions. I thought that you use reference parameters
when you have a function that needs to return more than one value, but can't you use pointers to accomplish the same task? when do you use one over the other? The only thing i can think of is the extra space required for declaring a pointer which is minimal.
Avatar of Oliver_Dornauf
Oliver_Dornauf
Flag of Afghanistan image

The the extra memory needs of pointer and refercences is the same (my be you mean call by value ?)
The point is : pointer for c gurus and references for object gurus, becouse you not need to play with the memory to much when use references.
To learn more about this try to use a reference to a pointer (char &*ptr) which is the object oriented style to declare an pointer to pointer :-;
ASKER CERTIFIED SOLUTION
Avatar of s_lavie
s_lavie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AssafLavie
AssafLavie

Use a pointer as the argument type if it makes sense to pass a NULL value. Otherwise, use a reference.