Insertion at head in linked list

#include

using namespace std;

class node{

    public:

            int data;

            node *next;

    node(int d)//constructor

    {

        data=d;

        next=NULL;

    }

};

void print(node *&q)

{

    while(q!=NULL)

    {

            cout<<q->data<<"->";

            q=q->next;

    }

}

void insertAtHead(node *&p,int d)

{

    if(p==NULL)

    {

            p=new node(d);

            return;

    }

    node *n=new node(d);

    n->next=p;

    p=n;

}

int main()

{

    node *head=NULL;

    int data;

    int n;

    cin>>n;

    for(int i=0;i<n;++i)

    {

            cin>>data;

            insertAtHead(head,data);

    }

    print(head);

    return 0;

}
please tell while printing linked list why can i not use pass by value instead of reference

hi @udaygupta2801_9701d724b34e371d u need to pass by value only it wont affect original list