I wrote the following c - codesnippet:
#include <stdio.h>
void function(int size){
int array[size];
for(int i = 0; i < size; i++){
printf("%d ", array[i]);
}
}
int main(){
int array_size;
scanf("%d",&array_size);
function(array_size);
return 0;
}
Why it is possible to generate an array of dynamic size this way. Normally I would use malloc, but this works as well. Why it is allowed to use the non constant variable size for the size of an array?