What does *&p do?

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2006
Posts: 61
Reputation: Eko is an unknown quantity at this point 
Solved Threads: 1
Eko's Avatar
Eko Eko is offline Offline
Junior Poster in Training

What *&p does?

 
0
  #1
Nov 30th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 275
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Solved Threads: 29
andor's Avatar
andor andor is offline Offline
Posting Whiz in Training

Re: What *&p does?

 
0
  #2
Nov 30th, 2006
If you want to win, you must not loose (Alan Ford)
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the C++ Forum


Views: 1059 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC