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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use a pointer as the argument type if it makes sense to pass a NULL value. Otherwise, use a reference.
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 :-;