Pass by pointer

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Pass by pointer

 
0
  #1
Oct 6th, 2005
Why in C++ passing a pointer is not termed as a parameter passing technique.....Is it because it has a flaw of some kind i.e. address is not reflected back/we can change the address in called function..is that so...if that's the reason....then we can pass it as const pointer as a remedy.....

Actually i am not sure that...changing address is flaw...

plz comment
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 164
Reputation: Stoned_coder is an unknown quantity at this point 
Solved Threads: 5
Stoned_coder Stoned_coder is offline Offline
Junior Poster

Re: Pass by pointer

 
0
  #2
Oct 6th, 2005
it is. passing a pointer is no different to passing anything else. Its a parameter the same as any other.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,377
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Pass by pointer

 
0
  #3
Oct 6th, 2005
It is indeed a parameter passing technique -- there are only two ways to pass something, by value and by reference. Pass by reference can be done in one of two ways -- a pointer (C) or reference operator (C++). The three differences I can think of
1. use of dot or pointer operators within the receiving function
  1. void foo(int* n)
  2. {
  3. *n = 0;
  4. }
  5.  
  6. void foo(int& n)
  7. {
  8. n = 0;
  9. }
2. use of '&' operator inside the passing function
  1. int main()
  2. {
  3. int n;
  4. foo(&n);
  5. foo(n);
  6. return 0;
  7. }
3. They can be overloaded functions as shown in the examples above.

Otherwise, the dot and pointer operator compile down to the same identical code. Its all really just a matter of programmer preference.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC