This post is about the small things I know about NULL value used in C and C++.
First and foremost: NULL is a macro (whateva the hell does it mean!)
NULL is actually used to check if a pointer is valid or not. Now, if you are aware of pointers, then you must be knowing that pointers actually store the address of variables in a memory. Since, they are storing the address, their count starts from 1(01,001,00001,00…001). The upper limit is memory dependent. For eg. for a memory of 1024 kb, the pointers value can maximum be= 1024*1024.
Hence, in c++ it is taken to be 0 in value. That is why, you may see in some sources it typecasted as (int)NULL to get value 0. Gross huh.!
NULL is not at all a thing to fear of. Try some statements like:
Actually, when I checked, I was getting following warnings in CodeBlocks:
converting to non-pointer type `char’ from NULL
NULL used in arithmetic
But actually speaking, they were just warnings. Try to avoid NULL, but when dealing with pointers, you cannot escape it. Moreover, it makes your code more readable and understandable.
Cheers and Happy codeing..!