fundamental difference between below mentioned while statements

This may be the lamest question of the day, but I am confused in below mentioned syntax.
I am creating the link list.

 
while(nodeptr->next!=NULL)

AND
 
while(nodeptr!=NULL)

AND
 
while(nodeptr)


Please if someone can help me understant these better, I am trying to use these insert, delete, append functions of the link list program.

Thanks a lot for your time.
while (nodeptr != NULL) is the same as while (nodeptr). The latter is a compact way to check whether any variable != 0. In this case it is used to check whether the pointer != 0, i.e,, it is not equal to NULL.

However, nodeptr->next is another pointer different from nodeptr.

Hence, while(nodeptr->next!=NULL) checks whether the "next" pointer is not equal to NULL.
Last edited on
thanks a ton abhishekm71 for explaining in such a discrete manner.. thanks again
Last edited on
You are welcome! Glad it helped.
Topic archived. No new replies allowed.