What is the difference between this two array definitions and which one is more correct and why?
#include <stdio.h>
#define SIZE 20
int main() {
// definition method 1:
int a[SIZE];
// end definition method 1.
// defintion method 2:
int n;
scanf("%d", &n);
int b[n];
// end definition method 2.
return 0;
}
I know if we read size, variable n
, from stdin
, it's more correct to define our (block of memory we'll be using) array as a pointer and use stdlib.h
and array = malloc(n * sizeof(int))
, rather than decalring it as int array[n]
, but again why?