NULL vs nullptr | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

NULL vs nullptr

What are the differences between NULL and nullptr? Is there a benefit for using one vs the other?

26th Oct 2022, 2:53 AM
Peter Nicholas
Peter Nicholas - avatar
2 ответов
+ 2
The difference is that NULL is an integer, nullptr is a pointer type. It is a crucial difference when dealing with (resolving) method overloads. They are not interchangeable*). When you talk pointer, always use nullptr. *) That is, think of them as not being interchangeable and always keep your types clear. Both are a 64bit zero, but the types are different, and the compiler will care about that difference.
26th Oct 2022, 9:42 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 3
Peter Nicholas NULL is passing 0 or NULL to mostly an int ( integer )version. And nullptr allows for both pointers and integers, usually passing nullptr to a pointer version.
26th Oct 2022, 4:25 AM
BroFar - avatar