468,537 Members | 2,035 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,537 developers. It's quick & easy.

doubt on Dangling pointer

Hi All,
I have a doubt on undrestanding Dangling pointers.Below I mentioned sample code. please let me know, my view on Dangling pointers is correct or not?
main( )
{
char *a,*b,*c;

a = (char *)malloc(40);
b = a;
c = b;
free(a);
/* now c is Dangling pointer*/
is it vorrect? if not please let know with Example program ?

Thanks
Sridhar.D
Feb 15 '08 #1
1 2114
weaknessforcats
9,207 Expert Mod 8TB
Yep. b is dangling also.

This is why there is grave danger in passing naked pointers throughout your code: You don't know when it's safe to free().
Feb 15 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

13 posts views Thread by Aravind | last post: by
11 posts views Thread by John | last post: by
20 posts views Thread by __PPS__ | last post: by
138 posts views Thread by ambika | last post: by
5 posts views Thread by Richard | last post: by
1 post views Thread by sekhar_ps | last post: by
3 posts views Thread by gsuresh | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.