943,940 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1582
  • C++ RSS
Nov 30th, 2006
0

What *&p does?

Expand Post »
I'm learning linked lists , and in my manual i have the following example.

  1.  
  2. #include <iostream>
  3.  
  4. using std::cout;
  5. using std::cin;
  6. using std::endl;
  7.  
  8. struct element
  9. {
  10. int info;
  11. element *address;
  12. };
  13.  
  14. void insertion(element *&p,int nr)
  15. {
  16. element *c;
  17. c=new element;
  18. c->info=nr;
  19. c->address=p;
  20. p=c;
  21. }
  22.  
  23. void print(element *p)
  24. {
  25. while(p!=0)
  26. {
  27. cout<<p->info<<endl;
  28. p=p->address;
  29. }
  30. }
  31.  
  32. int main()
  33. {
  34. int nr;
  35. struct element *p=NULL;
  36.  
  37. cout<<"Number =";
  38. cin>>nr;
  39. while(nr!=0)
  40. {
  41. insertion(p,nr);
  42. cout<<"Number =";
  43. cin>>nr;
  44. }
  45. print(p);
  46.  
  47. return 0;
  48.  
  49. }

Now , i understand the program ,except the first paramater of insertion (element *&p).
What does exactly means?Isn't element *p enough?Why we need the extra ampersand "&"?

thanks
Last edited by Eko; Nov 30th, 2006 at 8:24 am.
Similar Threads
Eko
Reputation Points: 12
Solved Threads: 1
Junior Poster in Training
Eko is offline Offline
60 posts
since Nov 2006
Nov 30th, 2006
0

Re: What *&p does?

Reputation Points: 251
Solved Threads: 29
Posting Whiz in Training
andor is offline Offline
274 posts
since Jun 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: C++, difficulties in choosing STL 's containers
Next Thread in C++ Forum Timeline: I need help please





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


Follow us on Twitter


© 2011 DaniWeb® LLC