Didnot understand why using & operator

void createLL(Node *&head,int a[],int n){
for(int i=0;i<n;i++){
InsertAtTail(head,a[i]);
}
}

void Print(Node *head)
{
Node *temp = head;
while(temp!=NULL){
cout<data<<" ";
temp = temp->next;
}
}

why are we suppose o use reference operator in insertion of data in linkedlist while not in case of printing it??

whenever in any function, you are modifying the linked list or changing the data, you pass it by reference ie. with & operator. Here print function is not modifying nay data in the linked list so it has not been passed by reference.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.