How, multidimensional array initilized dynaminically?

Showing Answers 1 - 15 of 15 Answers

vishal

  • Nov 30th, 2006
 

use the malloc function.

  Was this answer useful?  Yes

Naveen.B

  • Feb 18th, 2007
 

int arr[ROWS][COLS];
int **mp;
mp = arr;
for(i=0;i<ROWS;i++)
{
  mp[i] = (int *)malloc(COLS*sizeof(int));
}

  Was this answer useful?  Yes

Bond

  • Feb 18th, 2007
 

#define ROW 5    //Some value
#define COL  4    //Some value

int main()
{
     int **a;

     a = (int *)malloc(sizeof(int*) * ROW);    /* Allocating memory for a */

      for (i = 0; i < ROW; i++)
            a[i] = (int*) malloc(sizeof(int) * COL);   /* Allocating induvissual elements in array */
     
}

  Was this answer useful?  Yes

dasam

  • Apr 2nd, 2007
 

a) int **array1 = (int **)malloc(nrows * sizeof(int *)); for(i = 0; i < nrows; i++) array1[i] = malloc(ncolumns * sizeof(int));b) int (*array4)[NCOLUMNS] = malloc(nrows * sizeof(*array4));c) int (*array5)[NROWS][NCOLUMNS] = malloc(sizeof(*array5));

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions