Is it safe to delete a NULL pointer?

delete performs the check anyway, so checking it on your side adds overhead and looks uglier. A very good practice is setting the pointer to NULL after delete (helps avoiding double deletion and other similar memory corruption problems). I’d also love if delete by default was setting the parameter to NULL like in #define my_delete(x) … Read more

Why use pointers? [closed]

Why use pointers over normal variables? Short answer is: Don’t. 😉 Pointers are to be used where you can’t use anything else. It is either because the lack of appropriate functionality, missing data types or for pure perfomance. More below… When and where should I use pointers? Short answer here is: Where you cannot use … Read more

When to use references vs. pointers

Use reference wherever you can, pointers wherever you must. Avoid pointers until you can’t. The reason is that pointers make things harder to follow/read, less safe and far more dangerous manipulations than any other constructs. So the rule of thumb is to use pointers only if there is no other choice. For example, returning a … Read more