I am confused on the difference between static and dynamic arrays,in the examples part
what are some of the examples of the static and dynamic arrays
Collapse
X
-
Tags: None
-
There is no difference in how they work.
Static arrays are allocated at compile time by the compiler.
Dynamic arrays are allocated at run time by you using a memory allocation function.
Read this:
-
Static array haS fixed length.length is defined while initialization.
eg:int x[10];
they have reference address i.e index number.
Dynamic array does not have the fixed length. Yo can add or delete the element .
e.g int* y=new int[10];
delete[] y;
* is dereference .They are store in heap. "New" keyword have dynamix storage duration.Comment
-
The static array has fixed length because the compiler creates it at compile time.
The dynamic array has a length you decide because it is created at run time.
In both cases you cannot delete an array element. If the array is dynamic you can delete the array because you created it. If the compiler created the array, then only the compiler can delete it.
Did you read the "Arrays Revealed" link I sent you last time?Comment
Comment