943,692 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 16383
  • C++ RSS
Oct 6th, 2005
0

Pass by pointer

Expand Post »
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
Similar Threads
SpS
Reputation Points: 70
Solved Threads: 32
Posting Pro
SpS is offline Offline
598 posts
since Aug 2005
Oct 6th, 2005
0

Re: Pass by pointer

it is. passing a pointer is no different to passing anything else. Its a parameter the same as any other.
Reputation Points: 19
Solved Threads: 5
Junior Poster
Stoned_coder is offline Offline
164 posts
since Jul 2005
Oct 6th, 2005
0

Re: Pass by pointer

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
C++ Syntax (Toggle Plain Text)
  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
C++ Syntax (Toggle Plain Text)
  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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: I need some help for a C++ program
Next Thread in C++ Forum Timeline: C++ questions, How do they do it?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC