Thread: how to dynamically allocate double dimensional arrays/vectors with 'new'??

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    25

    how to dynamically allocate double dimensional arrays/vectors with 'new'??

    can anyone help me? its in a class.
    I Love Jesus

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Something like this -

    Code:
    int row =10;
    	int col =20;
    
    	int** arr = new int*[row];
    
    	for(int i=0;i<row;i++)
    		arr[i]=new int[col];
    
    	//do stuff
    
    	for(int j=0;j<row;j++)
    		delete [] arr[j];
    
    	delete [] arr;
    zen

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    154
    Originally posted by zen
    Something like this -

    Code:
    	int** arr = new int*[row];
    What does int ** mean? I've seen double asterisks a few places, but never an explanation of them.

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    53
    Pointing to something pointing to something!

    Of course....

    In this case, a pointer to an array of pointers. For TRUE dynamoism

    Ah.
    "Technology has merely provided us with a more efficient means for going backwards" - Aldous Huxley

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  2. allocate memory dynamically
    By rahulsk1947 in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2007, 04:30 PM
  3. Need some help/advise for Public/Private classes
    By nirali35 in forum C++ Programming
    Replies: 8
    Last Post: 09-23-2006, 12:34 PM
  4. Dynamically allocate a pointer?
    By theJ89 in forum C++ Programming
    Replies: 3
    Last Post: 04-09-2006, 02:03 PM
  5. Dynamically allocate size of array for strings
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 05-04-2002, 05:06 PM