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

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

struct element
{
    int info;
    element *address;
};

void insertion(element *&p,int nr)
{
    element *c;
    c=new element;
    c->info=nr;
    c->address=p;
    p=c;
}

void print(element *p)
{
    while(p!=0)
    {
        cout<<p->info<<endl;
        p=p->address;
    }
}

int main()
{
    int nr;
    struct element *p=NULL;

    cout<<"Number =";
        cin>>nr;
    while(nr!=0)
    {
        insertion(p,nr);
        cout<<"Number =";
            cin>>nr;
    }
    print(p);

    return 0;

}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.