I found out in C: null char == '\0' == NULLand I wrote a loop below to read from beginning to end char [] in C.
null char == '\0' == NULL
// case #1 char buf[32]; while (buf[i] != NULL){ //do something... }
However, my gcc compiler gave me a warning: a comparison between a pointer and an integer. Someone said that I misled two separate concepts: NULL for pointers, while "\ 0" for characters. Therefore, to get rid of the warning, I have to use '\ 0', since my loop checks for char.
Now I am writing a linked list and checking if the pointer points to the head of the node or not. Since it is structured, it is reasonable to use if (h1 == NULL), but apparently the compiler also compiles when I use if (h1 == '\0'), although node is a structure but not a char. Can someone help why both "\ 0" and NULL can be used in this case, until they can be used as in the first case?
if (h1 == NULL)
if (h1 == '\0')
// case #2 struct ListNode { int val; struct ListNode *next; };
. " " ( NUL, L, ) , . " " - , . - , . , , , .
C , , . , : 0 , NULL '\0'. , #define NULL 0 C. - , (T*)0 T, 0, NULL, , , (, execl).
0
NULL
'\0'
#define NULL 0
(T*)0
execl
, C int, char, '\0' - . ( ++ .)
int
char
โโC, IMNSHO '\0' , 0 - not NULL - .
NULL :
#define NULL ((char *)0)
#define NULL ((void *)0)
#define NULL 0L
NULL . 0 , , ListNode* 0 ( NULL , - ):
ListNode*
if (h1 == 0)
:
if (!h1)
A '\0' int C int ++. , '\0' .
'\0' ( 0) , NULL:
while (buf[i] != '\0') // or 0
while (buf[i])
NULL . '\0' (.. char)
If you had an array of structures, you may need to iterate over them until you reach the end:
MyStruct** things = ... for(int i = 0; things[i] != NULL; i++) { // Do something with things[i] }
This loop ends when the pointer to the last structure NULL.
Source: https://habr.com/ru/post/1608234/More articles:Base64 encoding or random string bin2hex - stringWhen deploying a Windows IoT application, an application activation error occurs locally - c #A shorter way to write python for a loop - pythonCocoa Touch Framework is no longer compatible with WatchKit extension? Do I need a Watch Framework? - iosWill the status of the โPending Developer Releaseโ application stop beta testing in Testflight - app-storeUnable to install pika using pip install - pythonSearch index in array in python - pythonJavaScript, Matter.js: disable collision for one organ - javascriptGet Token Index from stanford corenlp - nlpxcode 7 indexes forever ... will not compile - compilationAll Articles