1

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
1
  • Just an (off-topic) note for you: this is not the standard in C++ - you'd want to use a vector. Commented Feb 18, 2015 at 17:10

2 Answers 2

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

1

It is allocated on run time but on stack not on heap.

answered Feb 18, 2015 at 16:58

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.