Functions malloc, calloc, realloc and free are used to allocate /deallocate memory on heap in C/C++ language. These functions should be used with great caution to avoid memory leaks and dangling pointers. How are these functions different (or similar)?
Those who use languages like C and C++ that support user defined pointer variables, put utmost emphasis on implementing the pointers correctly. And rightfully so, A pointer wrongly handled can be catastrophic. And that’s an understatement 🙂 .
In my earlier articles on C++, I have written about the automatic type detection, uniform initialization list and Range based for loopin C++11. Earlier we used to use the NULL macro which is synonymous to int zero. This came as an inheritance from C language where 0 plays a double role (as an int and as NULL […]