I was reading about creating array dynamically in C. So the proper way as described there was:
int n;
scanf("%d", &n);
int *arr = (int*)malloc(n*sizeof(int));
But then I thought if I could just do something like this-
int n, i, sum=0;
scanf("%d", &n);
int arr[n];
And I compiled and ran it without any error. So, my question is why should I use malloc()
? Does this have something to do with the old and new C versions?