Pointers - need help understanding code
Code:
// Program to traverse a linked list#include <stdio.h>
int main (void)
{
struct entry
{
int value;
struct entry *next;
};
struct entry n1, n2, n3;
struct entry *list_pointer = &n1;
n1.value = 100;
n1.next = &n2;
n2.value = 200;
n2.next = &n3;
n3.value = 300;
n3.next = (struct entry *) 0; // Mark list end with null pointer
while ( list_pointer != (struct entry *) 0 ) {
printf ("%i\n", list_pointer->value);
list_pointer = list_pointer->next;
}
return 0;
}
I am having trouble understanding the "1st" time through the while loop. The "while ( list_pointer != (struct entry *) 0 )" is confusing me.
It's saying while (list_pointer is not equal to the null entry which is n3.next)
list_pointer=&n1 initially. List_pointer initially points to the n1 structure. But how can you set the n1 structure to != 0?
Can you set a structure to not equal the integer 0?