422,764 Members | 1,289 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,764 IT Pros & Developers. It's quick & easy.

what are some of the examples of the static and dynamic arrays

P: 1
I am confused on the difference between static and dynamic arrays,in the examples part
Mar 3 '18 #1
Share this Question
Share on Google+
3 Replies


weaknessforcats
Expert Mod 5K+
P: 9,134
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:
https://bytes.com/topic/c/insights/7...rrays-revealed
Mar 3 '18 #2

P: 1
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.
Mar 3 '18 #3

weaknessforcats
Expert Mod 5K+
P: 9,134
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?
Mar 4 '18 #4

Post your reply

Sign in to post your reply or Sign up for a free account.