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;
   }
}
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.

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.

Comments

Your Answer

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.