Thread: Difference between... (pointers)

  1. #1
    Registered User
    Join Date
    Aug 2001

    Wink Difference between... (pointers)

    What's that difference between

    int **foo;
    *foo = new int[x];
    for(int i = 0;  i < x;  i++)
        foo[i] = new int[y];

    int **foo;
    foo = new int*[x];
    for(int i = 0;  i < x;  i++)
        foo[i] = new int[y];
    which causes

    for(int i = 0;  i < x;  i++)
        delete [] foo[i];
    delete [] foo;
    crash in the first?
    Last edited by kooma; 02-13-2002 at 02:35 AM.
    kooma -

  2. #2
    Registered User Hoxu's Avatar
    Join Date
    Nov 2001
    dunno but it would be nice to know :P

  3. #3
    S­énior Member
    Join Date
    Jan 2002
    Deleting the first allocation isn't causing the crash, it's the actual allocation.

    int **foo;
    *foo = new int[x];

    You are de-referencing foo, but it doesn't point to anything. You need to point foo at something, then de-reference as you've done in the second example.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers
    By Big_0_72 in forum C Programming
    Replies: 3
    Last Post: 10-28-2008, 07:51 PM
  2. MergeSort with array of pointers
    By lionheart in forum C Programming
    Replies: 18
    Last Post: 08-01-2008, 10:23 AM
  3. vector destruction question
    By dudeomanodude in forum C++ Programming
    Replies: 4
    Last Post: 04-04-2008, 01:20 PM
  4. Pointers on pointers to pointers please...
    By Morgan in forum C Programming
    Replies: 2
    Last Post: 05-16-2003, 11:24 AM
  5. Replies: 1
    Last Post: 05-07-2002, 04:18 AM