Home:ALL Converter>C - Why must NULL be compared to?

C - Why must NULL be compared to?

Ask Time:2016-04-06T17:16:16         Author:Synlar

Json Formatter

I'm curious as to why when say I traverse a linked list iteratively I must do while (list != NULL) instead of while (!list). I thought NULL equated to zero or false.

From comments: My program seems to always crash when I attempt a while (!list) but never the former. Each node contains a void pointer to a piece of data and a pointer to the next node.

Author:Synlar,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/36446654/c-why-must-null-be-compared-to
axiac :

while (list != NULL) is not the same as while (!list). They are opposites! Of course your program crashes, it tries to de-reference a NULL pointer.\n\nwhile (list != NULL) is the same as while (list).",
2016-04-06T09:25:24
yy