I have done basic implementation of Linked List but its giving Segmentation fault on uncommenting the commented lines otherwise its working fine. I am not able to understand why its giving the error. Please give me some help
void insert(Node **head, Symbol sym) {
Node *temp, *p = *head;;
Symbol a = sym;
temp = (Node *)malloc(sizeof(Node));
temp->value = a;
temp->next = NULL;
if (p == NULL)
*head = temp;
else {
while (p->next != NULL)
p = p->next;
p->next = temp;
}
}
void printList(Node *head) {
Node *p = head;
if(p == NULL) return;
while (p != NULL) {
printf("%d ", p->value);
p = p->next;
}
printf("\n");
}
int main() {
Node *List, *list2;
insert(&List, 0);
insert(&List, 1);
//insert(&list2, 2);
//insert(&list2, 3);
printList(List);
return 0;
}
gdband step through.Node *List=NULL, *list2=NULL;