I wrote a C program. Some part of the code which is inside a function looks like this:
struct node* functionName(struct node *currentFirstPointer){
struct node **head = NULL;
*head = currentFirstPointer;
return *head;
}
Here node
is a structure. But this line gives me a segmentation fault
when I run the program. But if I declare and initialize the pointer to pointer in separate statements inside the same function like below then it works fine.
struct node* functionName(struct node *currentFirstPointer){
struct node **head;
*head = NULL;
*head = currentFirstPointer;
return *head;
}
What could be the reason that the 1st block doesn't work and the 2nd block works fine?