I'm currently learning how to code C and stumbled upon an interesting line,
Apparently,
struct node{
node *next;
};
node *head = (node *)calloc(1, sizeOf(node));
head->next = NULL;
node *currentNode = head;
while (!currentNode)
In this context, is
while(!currentNode)
different to
while(currentNode != NULL)
? I thought they meant to check for the same stuff, when current Node is not NULL but they are returning different results and I dont' understand...
while(currentNode)
and
while(currentNode != NULL)
are equivalent.
The first says that while currentNode
has some value (could be anything, even garbage), the second one says that while currentNode
is not NULL
, ie, has some value.
On the other hand,
while(!currentNode)
means that while currentNode
does not hold any value, ie, is NULL
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.