Linked List

hi all, I have a function that append node to a linked list like this:

struct ListNode{
int value;
struct ListNode* next;
};

void appendNode(struct ListNode* head, int num){
struct ListNode* nodePtr;
struct ListNode* newNode;
newNode = malloc(sizeof(struct ListNode));
newNode->value = num;
newNode->next = NULL;

if(!head)
head = newNode;
else{
nodePtr = head;
while(nodePtr->next)
nodePtr = nodePtr->next;
nodePtr->next = newNode;
}
}

int main(){
struct ListNode* head;
head = NULL;
appendNode(head, 5);
printf("%p", head);

return 0;
}

when I use it, the head in main() does not change its address and it's still pointing to NULL. Why??
Please use code tags.

Have not read your code (due to lack of code tags) but this should help:
http://www.cplusplus.com/articles/Lw6AC542/
oh please, its not THAT hard to read without the code tags
@gtm its not, it is however common practice and decency, to make it easier for someone from whom you want help and in addition I do believe I gave the OP a resource from which they will more than likely get their answer.
> the head in main() does not change its address value and it's still pointing to NULL. Why??
The function is modifying a copy of the pointer.
Topic archived. No new replies allowed.