I'm implementing a singly linked list using C.
struct Node 
{
    int nodeValue;
    struct Node* pNext;
};
struct Node* head;
void createList()
{
    head = (struct Node*)malloc(sizeof(struct Node));
}
void insertNodeAtBeginning(int value)
{
    struct Node* newNode;
    newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->nodeValue = value;
    struct Node* auxNode;
    if(head->pNext == NULL)
    {
        head->pNext = newNode;        
    }
    else
    {
        auxNode = head->pNext;
        head->pNext = newNode;
        newNode->pNext = auxNode;    //breakpoint set here
    }
}
I've set a breakpoint on line marked by the comment. The value of auxNode is non-NULL:
(gdb) p auxNode
$4 = (struct Node *) 0x5555555551db <createList+18>
However the value of newNode->pNext to which the auxNode is assigned is NULL:
(gdb) p newNode->pNext
$5 = (struct Node *) 0x0
Could anyone clarify this behavior? Thanks.
 
     
    