The nullptr keyword in C++: how it's better than NULL and how to use it correctly
Hello everyone. I recently started learning C++ and I'm confused about null pointers. In old textbooks and forums, they often write NULL, but in new examples I see nullptr. Both seem to mean "nothing" for a pointer, but the compiler sometimes complains about NULL.
Here's an example that confused me. I wrote a function that takes a pointer to int:
\n\nvoid print(int* ptr) {\n if (ptr == NULL) {\n std::cout << "Pointer is empty" << std::endl;\n } else {\n std::cout << *ptr << std::endl;\n }\n}\n\nvoid print(int value) {\n std::cout << "Integer: " << value << std::endl;\n}\n\nWhen I call print(NULL), the compiler (GCC with flag
No answers yet.
Log in to leave an answer