Search results for dangling pointer


            A pointer is called dangling pointer if 
Option A:

            it points to a deallocated memory.
Option B:

            it points to a void pointer.
Option C:

            it points to a NULL pointer.
Option D:

            it points to a memory which is allocated but not freed.
Correct Answer: option A

            ptr is ____ pointer after executing the following program?
#include <stdio.h>  
#include <stdlib.h>
void main()  
   int *ptr = (int *)malloc(sizeof(int));  
   int a = 5;  
   ptr = &a; 
   printf("%d\n", *ptr); 
Option A:

            NULL pointer
Option B:

            Void pointer
Option C:

            Dangling pointer
Option D:

            None of the above
Correct Answer: option C

            The dangling pointer errors can be avoided by
Option A:

            Allocating more memory using malloc
Option B:

            Assigning NULL value to the pointer after freeing allocated memory from the pointer
Option C:

            Assigning void value to the pointer
Option D:

            Deallocating memory from pointer using free.
Correct Answer: option B

 Search Links

 Popular C search MCQs

 Popular C search examples