pointers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anilk501
    New Member
    • Oct 2006
    • 7

    pointers

    what is dangaling pointers?
  • smartway
    New Member
    • Oct 2006
    • 24

    #2
    A dangling pointer is a pointer to storage that is no longer allocated.

    Comment

    • sowmyth
      New Member
      • Oct 2006
      • 19

      #3
      uninitialised pointers are called dangling pointers/stray pointers.it is so dangerous that it may sometimes cause the system to crash.
      i.e, instead of initialising a pointer like,
      int *p;
      we have to initialise it like ,
      int *p=0;
      or
      int *p=NULL;

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Originally posted by sowmyth
        int *p;
        int *p=0;
        int *p=NULL;
        None of these stop the pointer "dangling", you write to any of these pointers and you are likely to get very undesireable behaviour.

        These are effectively all uninitialise pointers but if you set the uninitialised pointer to o (or NULL) then you can at least detect it.

        Before writing to the pointer you must initialise it

        Code:
        p = malloc(sizeof *p);

        Comment

        Working...