In C, what is the null value? What does it mean?
For more information, see du Niang. Here we will only describe my understanding of the null value.
Simply put, the null value represents "inaccessible ".
See the following example:
# Include <stdlib. h> <br/> # include <stdio. h> <br/> # include <string. h> </P> <p> int main (INT argc, char * argv []) <br/> {<br/> char * s; <br/> S = (char *) malloc (10 * sizeof (char); <br/> If (S = NULL) {<br/> printf ("malloc error! /N "); <br/> return-1; <br/>}< br/> memset (S, 0, 10 * sizeof (char )); <br/> If (S = NULL) {<br/> printf ("Something error! /N "); <br/> return-1; <br/>}< br/> memset (S, '0', 10 * sizeof (char )); <br/> If (S = NULL) {<br/> printf ("Something error2! /N "); <br/> return-1; <br/>}< br/> printf (" All OK! /N "); <br/> return 0; <br/>}
What is the final result of this example? Yes all OK!
If you change char * s to Char s [10]; or char s [];
The result will be clearer. The same is all OK!
Question:
The definitions of char * s and char s [] are different in C language implementation. The latter determines the variable during compilation and assigns the address to it;
Char * s is dynamically generated during running. Therefore, the former requires memory allocation and check if (S = NULL), if s! = NULL,
The variable is allocated successfully!
Based on this, whether the null value is 0, '0', or (void *) 0 is actually not important. They are different definitions of different compilers, just superficial phenomena.
In essence, null indicates that the address is inaccessible!
For personal opinions, please contact us!