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;
}
}
asked Feb 18, 2015 at 16:56
-
Just an (off-topic) note for you: this is not the standard in C++ - you'd want to use a vector.Matt– Matt2015年02月18日 17:10:14 +00:00Commented Feb 18, 2015 at 17:10
2 Answers 2
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.
answered Feb 18, 2015 at 16:58
Sign up to request clarification or add additional context in comments.
Comments
It is allocated on run time but on stack not on heap.
answered Feb 18, 2015 at 16:58
Comments
lang-c