Reputation: 21
Is the memory to variable arrays allocated during run-time or compile-time in c?
int n;
printf("Enter size of the array: ");
scanf("%d",&n);
int a[n];
for(int i=0; i<n; i++)
{
a[i] = 0;
}
}
Upvotes: 1
Views: 70
Reputation: 20005
Since the size n
of the array is defined at runtime, then also the allocation happens in the runtime.
The memory is allocated from the stack, which is faster than allocating from the heap. But how much memory you can reserve is much lower.
Upvotes: 2