Null Pointer Assignment in C | Null Pointer concept in c
It does make sense to assign an integer value to a pointer variable. An exception is an assignment of 0, which is sometimes used to indicate some special condition(Null pointer).
A macro is used to represent a null pointer. That macro goes under the name NULL. Thus, setting the value of a pointer using the NULL, as with an assignment statement such as ptr = NULL, tells that the pointer has become a null pointer. Similarly, as one can test the condition for an integer value as zero or not, like if (i == 0), as well we can test the condition for a null pointer using if (ptr == NULL) or you can even set a pointer to NULL to indicate that it’s no longer in use.
# include# define NULL 0 main() { int *pi = NULL; printf(“The value of pi is %u”, pi); }
No comments:
Post a Comment