Logo

Programming-Idioms

History of Idiom 26 > diff from v5 to v6

Edit summary for version 6 by :

Version 5

2015-08-19, 17:12:57

Version 6

2015-08-20, 10:15:37

Idiom #26 Create a 2-dimensional array

Declare and initialize a matrix x having m rows and n columns, containing real numbers.

Idiom #26 Create a 2-dimensional array

Declare and initialize a matrix x having m rows and n columns, containing real numbers.

Imports
#include <stdlib.h>
Code
double **x=malloc(m*sizeof(double *));
int i;
for(i=0;i<m;i++)
{
	x[i]=malloc(n*sizeof(double));
}
Comments bubble
Uses dynamic allocation.

If the values of m and n are known at compile time you can also use:

double x[m][n];