Exforsys
+ Reply to Thread
Results 1 to 4 of 4

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 ...

  1. #1
    Ralph is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    114

    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.


  2. #2
    Rahulbatra is offline Senior Member Array
    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.


  3. #3
    Ralph is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    114
    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.


  4. #4
    Rahulbatra is offline Senior Member Array
    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



Latest Article

Network Security Risk Assessment and Measurement

Read More...