Hi, I got an assignment of doing a program to make the sum, substraction, etc. of a matrix A and a matrix B of given dimensions (Via keyboard, via detection, any method was possible).
I used dynamic memory allocation with three double ** A, **B, **C and used calloc to create the 2 dim arrays but, then I found this code on the net:
Code:
#include<stdio.h>
int main(){
int N,M,L;
printf("Number of rows in Matrix A: ");
scanf("%d",&N);
printf("Number of columns in Matrix A: ");
scanf("%d",&M);
printf("Number of columns in Matrix B: ");
scanf("%d",&L);
double A[N][M],B[M][L],C[N][L];
// REST OF CODE
return 0;
}
No warning, compiles, and is shorter than memory allocation, as far as I know, array dimensions must be const int but here they are read from the stdin with a plain scanf and it surprisingly works. Is there anything wrong with doing this?