What type of error is this

/bin/run.sh: line 4: 18 Segmentation fault (core dumped) ./exe
//

#include
using namespace std;
class node{
public:
int data;
node* next;
//constructor
node(int d){
data = d;
next = NULL;
}
};
void insertAtHead(node*&head , int data){
node n = new node(data);
n->next = head;
head = n;
}
int length(node
&head){
int len = 0;
while(head !=NULL){
head = head->next;
len +=1;
}
return len ;
}
void insertAtTail(node*&head, int data)
{ if(head == NULL){
head = new node(data);
return ;
}
nodetail = head;
while(tail->next!= NULL){
tail = tail->next;
}
tail->next = new node(data);
return ;
}
void insertInMiddle(node
&head , int data,int p){
if(head == NULL || p == 0){
insertAtHead(head,data);
}else if(p >length(head)){
insertAtTail(head,data);
}else{
//insert at middle
// p-1 jump
int jump = 1;
node* temp = head;
while( jump<=p-1){
temp = temp->next;
jump +=1;
}
node *n = new node(data);
n->next = temp->next;
temp->next = n;
}
}

void print(nodehead){
node
temp = head;
while(temp!= NULL){
cout<data<<" ";
temp = temp->next;
}

}
int main() {
node*head = NULL;
insertAtHead(head,5);
insertAtHead(head,4);
insertAtHead(head,3);
insertAtTail(head,6);

insertInMiddle(head,2,3);
print(head);

return 0;

}

@abhinav17 this is a segmentation fault. It means that you tried to access a memory location that is not there. In this case, probably tried to access a NULL pointer. Please save your code on ide.codingblocks.com and share the link so I can help you with debugging.

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.