Difference between null pointer and dangling pointer?

Answers were Sorted based on User's Feedback



Difference between null pointer and dangling pointer?..

Answer / vrushali

NULL pointer points to nothing.
But dangling pointers are those pointers which points to
invalid location (e.g. still points to those memory
locations which are already freed)

int *p = NULL;
Is mere a pointer which is not initialised to valid
memroy location. it points to nothing

int *q ;
q -> 0x1A
free (q);

still we can access this pointer using q. Still memory has
not been released to the system.

Is This Answer Correct ?    27 Yes 5 No

Difference between null pointer and dangling pointer?..

Answer / rakshitha

Null pointer is a pointer which doesnot point to any where
in the memory location ,where as dangling pointer points to
memory location having garbage value.

Is This Answer Correct ?    8 Yes 1 No

Difference between null pointer and dangling pointer?..

Answer / vrushali

free should be able to free as it maintains a table from
where it can start freeing the memory. It is OS related issue.

There is no way in C where we can ensure that the particular
memory is freed a even after free we can access the variable
for some time. In Java, we have a memory deallocator.

Is This Answer Correct ?    5 Yes 1 No

Difference between null pointer and dangling pointer?..

Answer / vadivel t

To Sourisengupta Question.

free() shall free the memory which is allocated dynamically.

But afrer the free() function being called,the pointer
which u r passing to free() as an argument, shall point to
the same base address, which is no more valid.

Is This Answer Correct ?    2 Yes 0 No

Difference between null pointer and dangling pointer?..

Answer / vadivel t

Minor correction in my ans #4...

To Sourisengupta Question.

free() shall free the memory which is allocated dynamically.

But afrer the free() function being called,the pointer
which u r passing to free() as an argument, shall point to
the same base address, which is no more valid(ie., address
is valid but no more in the allocated memory pool. It will
be added in the free memory pool).

Is This Answer Correct ?    2 Yes 1 No

Difference between null pointer and dangling pointer?..

Answer / ravi

Both are very different.
NULL macro is
#define NULL 0
it means the macro NULL will be replaced by 0 while
preprocessing
But the NULL pointer means it points to nowhere i.e. contains 0.
It contains 0 means it may be dangerous to use such pointer
without assigning proper address to it otherwise NULL
pointer may try to access reset address may cause the
program to crash.

Is This Answer Correct ?    0 Yes 0 No

Difference between null pointer and dangling pointer?..

Answer / sourisengupta

If free() is not able to free the memory then how we are
freeing the memory????

Is This Answer Correct ?    4 Yes 6 No

Post New Answer

More C Interview Questions

Do you know null pointer?

0 Answers  


Write a c program to read a positive number and display it in words.? ex: 123=one two three help me....

2 Answers  


What is C language ?

0 Answers   Jekson,


a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list

0 Answers  


please tell me the logic for this C program : INPUT (string):ABCD OUTPUT :BCDA CDAB DABC

2 Answers   Mphasis,






What is variable declaration and definition in c?

0 Answers  


Write a program to check armstrong number in c?

0 Answers  


Explain what will be the outcome of the following conditional statement if the value of variable s is 10?

0 Answers  


Can you please explain the difference between malloc() and calloc() function?

0 Answers  


#include<stdio.h> main() { int i=5; printf("%d",i*i-- - --i*i*i++ + ++i); } tell the answer with correct reason .specially reason is important nt answer ans by turbo c is -39

1 Answers   GameLoft,


Add 2 64 bit numbers on a 32 bit machine

3 Answers   EMC, Hyderabad Central University, NetApp,


write the output of following code .. main() { static int a[]={10,20,30,40,50}; int *ptr=a; static int arr[2][2]={1,2,3,4}; char str[]="ABCD * 4#"; char *s=str+2; int i,j; for(i=0;i<5,i++) printf("%d",*ptr++); for(i=0;i<2;i++) for(j=0;j<2;j++) printf("%d\n",*(*(n+i)+j)); printf("%c\n%c\n%c\n",*(str+2),*s++,*--s); }

1 Answers  


Categories