Which of the following is not a consequence of using a dangling pointer?Marks : 1Negative Marks : 0Answer hereMemory leakSystem crashSegmentation faultNone of the mentioned options
Question
Which of the following is not a consequence of using a dangling pointer?Marks : 1Negative Marks : 0Answer hereMemory leakSystem crashSegmentation faultNone of the mentioned options
Solution
The correct answer is "Memory leak".
Here's why:
A dangling pointer is a pointer that doesn't point to a valid object. This can occur when an object is deleted or deallocated, without modifying the value of the pointer, so it still points to the memory location of the deallocated memory.
-
Memory leak: This is not a consequence of using a dangling pointer. A memory leak occurs when programmers create a memory in heap and forget to delete it. Memory leaks are particularly serious issues for programs like daemons and servers which by definition never terminate.
-
System crash: This can be a consequence of using a dangling pointer. If a program tries to access memory through a dangling pointer, it could cause the program to crash.
-
Segmentation fault: This can also be a consequence of using a dangling pointer. A segmentation fault occurs when a program tries to access a memory location that it's not allowed to access, which can happen when dereferencing a dangling pointer.
-
None of the mentioned options: This is not the correct answer because both system crash and segmentation fault are potential consequences of using a dangling pointer.
Similar Questions
Which of the following scenarios can lead to a dangling pointer?Marks : 1Negative Marks : 0Answer hereReturning a pointer to a local variable from a functionUsing malloc() for memory allocationAssigning a pointer to another pointerDeclaring a pointer inside main()
In which case does a pointer become a dangling pointer?Marks : 1Negative Marks : 0Answer hereWhen it is declaredWhen it is used to allocate memoryWhen the memory it points to is reallocatedWhen the memory it points to is deallocatedClearNext
Which of the following is not a consequence of using a dangling pointer?
What is the result of dereferencing a dangling pointer?Marks : 1Negative Marks : 0Answer hereThe program crashes.The pointer is set to NULL.The value at the memory location it points to.A compilation error.
How can you prevent creating dangling pointers?Marks : 1Negative Marks : 0Answer hereAvoid using pointers altogether.Always set pointers to NULL after memory is deallocated.Always assign pointers to the addresses of global variables.None of the mentioned options
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.