
- Forum
- Programming Talk
- C and C++
- To make Dangling pointer
To make Dangling pointer
This is a discussion on To make Dangling pointer within the C and C++ forums, part of the Programming Talk category; I have a portion of extract of my code as below struct node *test(int inp) { struct node *t; t ...
-
To make Dangling pointer
I have a portion of extract of my code as below
struct node *test(int inp)
{
struct node *t;
t = (struct node *) malloc(sizeof(struct node));
.........
........
return t;
}
I want to make the pointer t as dangling pointer .Someone suggests me a way for achieving this.
-
05-16-2007, 04:33 PM #2
- Join Date
- Apr 2006
- Answers
- 124
Your t is already a dangling pointer because t is defined within the scope your function test and when it is returned it results in pointing to a object which does not exists thus resulting in dangling pointers.
-
But my program did not give any error or warning and neither crashed. It is amazing being used as dangling pointers how my program worked. Kindly explain me on this.
-
05-18-2007, 04:03 PM #4
- Join Date
- Apr 2006
- Answers
- 124
It is not essential or mandatory that your program should crash if you have used dangling pointers. But you would get program crash if you use automatic variables in that memory defined in your C program and try to use that after usage of dangling pointers in your program. Make a try in this way and you would see your program crash.
-
Sponsored Ads

Reply With Quote





