Insertion in the circular linked list

void insertathead(nodehead,int d){
if (head==nullptr){
head=new node(d);
return;
}
node
n=new node(d);
node* temp=head;
while(temp->next!=head){
temp=temp->next;
}
n->next=head;
temp->next=n;
head=n;

}

i have written this code for insertion what is the problem in this and

also why you make a self loop in the list to the new node

hey @nimit_jain please share this code using ide.codingblocks.com

that’s how circular linked list works that is tail is connected with the head.
new_node->next = head;