N
none
I currently building a library that I would like to use in
both C++ and C projects. I want to use a NxM multidimentional
array, so I'm trying to make it in C. I tried this code:
int **array=(int **)malloc( 3 * sizeof(int*));
for (int M=0; M < 3; M++) {
array[M]=(int*)malloc(3 * sizeof(int));
}
array [0][1]= 1;
array [1][2]= 2;
printf ("[%2i][%2i]",array[0][1],array[1][2]);
but it doesn't work in my cpp visual studio project, should it
work in c++? or am I doing something wrong? the values
printed on screen are not 1 and 2.
thanks in advance.
both C++ and C projects. I want to use a NxM multidimentional
array, so I'm trying to make it in C. I tried this code:
int **array=(int **)malloc( 3 * sizeof(int*));
for (int M=0; M < 3; M++) {
array[M]=(int*)malloc(3 * sizeof(int));
}
array [0][1]= 1;
array [1][2]= 2;
printf ("[%2i][%2i]",array[0][1],array[1][2]);
but it doesn't work in my cpp visual studio project, should it
work in c++? or am I doing something wrong? the values
printed on screen are not 1 and 2.
thanks in advance.