Problem in link list

This is a discussion on Problem in link list within the C Programming forums, part of the General Programming Boards category; Hi,
I have create a simple program for displaying a link list,but it is not working properly.
The code is ...

The problem is that in insert(ptr) function it always showing the ptr value 0 i.e NULL which I don't understand since the ptr I have declared as global so it should not be initialized to 0 every time the loop runs.
Can anybody explain me the behavior and solution to it.

Pointers themselves are passed by value. your global ptr is not modified by passing it to insert. To do that you'd need to either return ptr as well or prototype the function to take a pointer to a pointer, and pass it that.