Hi!
I have a confusion regarding NULL macro.
Since ascii value of NULL is 0 ,so instead of using 0 why we used NULL macro for comparison
purpose.
Is it due to logical reason or something else?
Please explain it...
Thanks
Bargi
Hi!
I have a confusion regarding NULL macro.
Since ascii value of NULL is 0 ,so instead of using 0 why we used NULL macro for comparison
purpose.
Is it due to logical reason or something else?
Please explain it...
Thanks
Bargi
when you read the code
p == NULL - you understand that here it suposed to be used the pointer comparison
when you see
p == 0 - you cannot be sure is this code suppose to be
p == NULL
or
*p == 0
Also when you write
*p == NULL compiler will warn you that you comparing pointer value to non-pointer value...
So using this macro helps to prevent different typing errors
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
> So using this macro helps to prevent different typing errors
There is no right answer.
http://c-faq.com/null/nullor0.html
In C, NULL is often defined as ((void *)0) which makes it impossible to accidently do:
int x = NULL;
In C++ NULL cant be defined with a cast to void * because void * cant be converted to any other type automatically