[Dev-C++] Pointers vs 2-D Arrays: feedback
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <and...@su...> - 2007-09-24 17:41:38
|
Thank you guys!
Now I can make refferences for elements in
a N-D array dynamically allocated.
Translating your help for the old school style,
the final code became:
///////////////////////////////////////////////////////////////////////
/* using a 2-row 3-column array */
#include <stdio.h>
#include <stdlib.h>
int main()
{
double **matriz;
int i, j, k;
matriz = (double **) malloc(2*sizeof(double));
for(j=0; j<3; j++) matriz[j] = (double *) malloc(3*sizeof(double));
k=0;
for(i=0; i<2; i++)
for(j=0; j<3; j++)
matriz[i][j] = ++k;
for(i=0; i<2; i++){
for(j=0; j<3; j++)
printf(" %lf ", matriz[i][j]);
printf("\n");
}
free(matriz);
system("PAUSE");
return 0;
}
//////////////////////////////////////////////////////////////////////
Best Regards
Andre
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.13.30/1027 - Release Date: 24/9/2007
11:27
|