As far as my knowledge about c/c++ goes, NULL it's just a named constant for the value zero... So Why do i use NULL instead of just using 0? it's quite simple, code organization, every time i have to start a pointer, i set it to NULL, because just of seeing the name, i know that the object/variable will be a pointer,
Look at these two lines
int a = 0;
int a = NULL;
or
int *a=0;
int *a=NULL;
the result int this lines will be always the same, but for a programmer that will read the code, it's much more intuitive to read a pointer as NULL and an integer as zero..
And also, NULL it's the oficial address for nothing, so if the ANSI want to change this value from 0 to 2E-10 and you always use the named constant, than you'll have no problem with that, but if you use zero, than you'll have to change all the code you made before...
The second thought is just a little terrorism, i use NULL because of the organization and easy understanding... and with my experience i can assure you, sometimes a little organization can save a lot of time when you're debuging and looking for errors in your code...
Originally posted by mif
Hey all c++ programmers!
can anyone tell me what is the difference between using
int *r = 0 vs. int *r = NULL?
why do you use one over the other?
Thanks~