I researched a lot of static and dynamic memory allocation but still, there is a confusion that:
int n, i, j;
printf("Please enter the number of elements you want to enter:\t");
scanf("%d", &n);
int a[n];
for (i = 0; i < n; i++)
{
printf("a[%d] : ", i + 1);
scanf("%d", &a[i]);
}
Does int a[n]
come under static or dynamic memory allocation?
malloc
-family of functions and heap allocation, but this is definitely not static allocation, so it's not weird that you are confused with how to clasify it. So, yes, this falls under the third type, "automatic allocation". In this casea
is a variable-length automatic array. Note that the actual place where this array will be stored is implementation dependant, C does not deal with stacks and heaps. – Font