Do you use NULL or 0 for the pointer?

Asked 2 years ago, Updated 2 years ago, 25 views

In the beginning, NULL cannot be used for C++, and only void* type can be assigned, so I wrote (void*)0 together, but these days, it is possible to assign NULL to the pointer.

I usually use (void*)0 and my friends seem to use NULL more. But I don't know the advantages of NULL

If you use (void*)0,

if (p && !q)
  do_something();

Since p is 0, it makes sense to write true/false NULL doesn't know if it's 0 or not, so shouldn't you write p &&!q and compare it with NULL?

What is the difference between 0 and NULL? Do I just write whatever I want?

c++

2022-09-22 13:53

1 Answers

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.