Thread: Wild Pointers?!!

  1. #1
    Registered User
    Join Date
    May 2003

    Wild Pointers?!!

    I'm currently learning about Pointers...
    The book says that wild pointers " pointers that are not initialized " are VERY dangerous!

    why are they dangerous ?
    I have a code which stops life!

  2. #2
    Registered User
    Join Date
    Jul 2003
    Because they don't point to anything, meaning they could crash your program. Also read up on pointers, after you are done you should intialise them to NULL.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    An uninitialised pointer could point to any location. So if you;

    int* ptrI;
    *ptrI = 10;

    It may work once or twice (because the location of the pointer may point to a safe area of memory), but then crash without warning then next time.

    If you;

    int* ptrI = 0;
    *ptrI = 10;

    Then it will crash every time, but the reason for the crash given by your debugger or the os gives you good hint to look for a point in your code where you dereference a null pointer

  4. #4
    Registered User
    Join Date
    May 2003
    Uninitialized pointerse point to a location in mem. If you don't assign them values, they use the values that are already in the little ram piece they've selected.

    try this and see for yourself:

    int* x;
    cout << *x;
    Very annoying.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. wild pointers
    By ravi rajeev in forum C Programming
    Replies: 3
    Last Post: 04-02-2007, 05:39 AM
  3. Request for comments
    By Prelude in forum A Brief History of
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM