Regarding pass by reference in insertion in linked list

in the function InsertAtHead(node* &head,int d)
we do node* temp=head. why didn’t we do node* temp = *head as we do in other cases in pass by reference??

Hello @apurvaraina99,

As the head is itself a pointer variable pointing the first node of the linked list i.e. contains the address of the first node of the linked list.

when you write:
node* temp=head;
you are creating a pointer variable(temp) of type node and assigning the value stored in head i.e. the address of the first node of the linked list.

and by writing:
node* temp = *head;
you are assigning the value stored at the address stored in head variable, which might give an error.

Hope, this would help.
Give a like if you are satisfied.

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.