I know that you are supposed to use 0
instead of NULL in c++ (even though NULL
is defined as 0
in C++ most of the time).
Recently I came across some code where 0x0
was used instead, though.
What is the difference?
Null Values can be replaced in SQL by using UPDATE, SET, and WHERE to search a column in a table for nulls and replace them. In the example above it replaces them with 0.
Since the zero page can be mapped and therefore 0x0 is a valid address, the zero bit pattern should not be used for the null pointer.
The C standard defines that 0 is typecast to (void *) is both a null pointer and a null pointer constant.
Instead of NULL , they use nullptr , a new keyword introduced in C++11. Like NULL , nullptr implicitly converts to T* for any type T . Unlike NULL , nullptr is not an integer so it cannot call the wrong overload. Unlike NULL , nullptr has its own type, nullptr_t , so the compiler makes correct type deductions.
0x0
is just 0
written in hexadecimal notation. There is no difference between the two:
016 = 010 :)
NULL
is usually #define
d to 0
somewhere and does the same thing.
There is no difference. In C, NULL is often defined to be (void *)0
, but in C++ that's not allowed. A few ancient compilers got this wrong, but they really are ancient.
IMO, it's better to use NULL, as it portrays the intent more clearly, and gives you a nice, easy symbol to S&R when your compiler gets updated to C++ 0x, which will include nullptr
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With