2
$\begingroup$

I am trying to learn CS fundamentals and I am confused by static vs dynamic allocated arrays. My only programming experience is JavaScript and all online resources I am using refer to C language.

A dynamic allocated array is made when the application starts and it cannot be resized. So how is this different from static allocated array, if to expand the array you have to make a new and bigger array and copy over the contents?

$\endgroup$

closed as off-topic by Evil, jmite, David Richerby, Juho, hengxin Dec 5 '16 at 11:46

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development or programming tools are off-topic here, but can be asked on Stack Overflow." – Evil, jmite, David Richerby, Juho, hengxin
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ I think that this question is better suited at Stack Overflow because it is a programming issue. $\endgroup$ – Evil Nov 17 '16 at 22:01
  • $\begingroup$ By static do you mean the memory in the function that is preserved between calls or the memory that is automatically created and destroyed? To avoid further confusions VLA (variable length arrays in C) are also not resizeable. If you want resizeable memory maybe realloc would be helpful, but it also copy the array to new location if in the current is not enough place for resize (increasing the array). $\endgroup$ – Evil Nov 17 '16 at 22:09
  • 2
    $\begingroup$ This has already been explained here: stackoverflow.com/questions/8385322/… $\endgroup$ – fernando.reyes Nov 18 '16 at 0:00
3
$\begingroup$

No, a dynamically allocated array is created when the program creates it, in the size the program wants to create it, and it exists until the point of time when the program destroys it.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.