11. What is Dangling Pointer ?
Dangling pointers arise during object destruction, when an object that has an incoming reference is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory.
12. How to avoid Dangling pointers?
A popular technique to avoid dangling pointers is to use smart pointers. Smart pointer is a pointer-like type with some additional functionality, e.g. automatic memory deallocation, reference counting etc.Avoiding a dangling pointer is more of a programmer’s exercise than any other techniques. You should be vigilant about when you are free-ing memory and make sure that you reference them to NULL so as to not create cases of a dangling pointer. You can create a user-defined function where you can pass the pointer , free the memory and explicitly set them to NULL . This can be a way to avoid cases of Dangling Pointers.
13. What are the disadvantages of linked lists?
They use more memory than arrays because of the storage used by their pointers.
Difficult in reverse traversing. Singly linked lists are cumbersome to navigate backwards and while doubly linked lists are somewhat easier to read, memory is wasted in allocating space for a back-pointer.
Nodes in a linked list must be read in order from the beginning as linked lists are inherently sequential access.
Nodes are stored incontiguously, greatly increasing the time required to access individual elements within the list, especially with a CPU cache.
14.What is a linked list?
A linked list is a linear data structure where each element is a separate object. Each element of a list is comprising of two items – the data and a reference to the next node. The last node has a reference to null. The entry point into a linked list is called the head of the list.Each element in a linked list is called a node.
15.What do you mean by garbage collection
Garbage collection (GC) is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program. Garbage collection is essentially the opposite of manual memory management, which requires the programmer to specify which objects to deallocate and return to the memory system.