Think about the scope. When you use a while loop in your program, a pair of curly braces is used. It means that your newly created node can only survive between the curly breaces. Every time the loop body is carried out, the memory will be recycled. Note that when you get in the loop body, the system allocate the memory from stack, which will be recycled. But malloc() will allocate from the heap, which need to be managed by your self. So malloc() can continuously gives you a new node. Hope it's helpful! :)