Thread: double arrays

  1. #1

    double arrays

    I need an array of dimension NxN but I need to malloc instead of doing 'int a[N][N];' and read in integers. I tried the following:

    int ..........;
    a=(int **)malloc(N*sizeof(int**));
    and (a+i+j) to store the scanned value using nested for loops. It's not working since a+1+0 is the same as a+0+1

    could anyone help? C or C++

    *new programer*

  2. #2
    first the proper declaration is
    int **a;
    first you have to allocate space so that a can hold N pointers
    a= mallco(N*sizeof(int *));
    the loop through i to allocate space for N elements in each of of the N pointers

    a[i] or *(a+i) is the pointer to the ith row
    so the i,j element is *(*(a+i)+j) or a[i][j] or *(a[i]+j),

  3. #3
    thanks, I just figured out how to do it.


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. C++ to C Conversion
    By dicon in forum C Programming
    Replies: 7
    Last Post: 06-11-2007, 08:38 PM
  3. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 06:54 PM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  5. needs help copying arrays
    By RedRattler in forum C Programming
    Replies: 3
    Last Post: 04-04-2003, 11:34 PM