Not able to understand why this is not giving correct ouput

void insertAtTail(node*&head, int d){
if(head == NULL){
head = new node(d);
return;
}

node * new_node = new node(d);
node* tail = head;
while(tail->next == NULL){
    tail = tail->next;
}
tail->next = new_node;

}

@Nitishkumar9711 please send the full code using cb ide
but considering this code you havent updated tail at last
do tail = new_node in last

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.