Null pointers in a Binary tree
Given a Binary Tree with n Nodes (you may arrange these nodes any way you want to). How many NULL pointers will be there ? You want options also :).. here are the options A) n B) n+1 C) n-1 D) None
Difference between malloc, calloc, free and realloc functions
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)?
Memory leaks and dangling pointers
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 🙂 .
Separate nullptr in C++11
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 […]
Changing pointer passed to a function as argument
If a function in C/C++ takes a pointer argument and we try to change it (Not the value pointed to by pointer but the pointer itself). It should be done with caution to avoid undesired results …
Freeing memory allocated to n-dim array using free
Yesterday we learned about how to allocate memory on heap for an n-dim array using Malloc. Today let us see how to deallocate the memory on heap using free. It is Simple if we are deallocating normal pointers or pointers pointing to a one-dimensional array. How will deallocate memory of an n-dim array on heap?
Allocating memory to n-dim Array on heap
Dynamic arrays are on heap. If an array is stored on heap, its address must be stored in pointer variables, else there will be no way to access the array. Let us assume the Array to hold integers. Write a code to allocate memory to a 2-dim array and then generalize it to allocate memory […]
difference between reference & pointers in C++
What is the difference between reference & pointers in C++? Is it safe to use pointers in places where we use reference & vice-versa?