why sometimes we are taking node*&head and sometimes node*head ??
Linked list passing parameter
Hi Ashish,
Using the ‘&’ sign with an argument signifies we are passing it by reference . Otherwise the argument is passed by value . If we pass the argument by reference , any changes made to such argument in the function are reflected back in the original argument where we made the function call.
Hence in some functions like where we want to update the linked list like insertAtTail( ) or build( ) , we pass the head pointer of the Linked List by reference( node*&head) as we want the changes made to reflect back in the original pointer in the main( ).
In some other functions like print( ) or length( ) where we do not intend to make any changes to the original pointer , we simply pass it by value without using the & sign - node * head.