What is dangling pointer? If a pointer refers to an invalid memory location, then it is called dangling pointer. Consider any pointer that points to a newly allocated memory block. If the newly allocated block is freed without modifying the pointer value, then the pointer will point to the deallocated memory block. So, corruption might occur if the user tries to perform write operation in the memory block pointed by dangling pointer. In most cases, user can observe segmentation fault when he tries to free/dereference a dangling pointer. int *ptr , *tmp; ptr = (int *)malloc(sizeof(int)); tmp = ptr; free(ptr); *tmp = *tmp + 10 Here, tmp is a dangling pointer since it points to the freed memory block. Below is an another example for dangling pointer. int *ptr; { int ch = 10; ...
The Only Shot to You need to kickstart your programming in any language