Dynamic array

Hi everyone, i have a doubt that is it compulsary to make dynamic array d=new[some_size]; before we use in some logic???
for example,

int d;
foreach(d[i])
//some logic
as the name is dynamic array it should capable of expanding and compress on its own right???

In reply to avpchandra:

Dynamic array gets memory allocation only when its assigned with =new[some_size]. The one which gets expanded or allocated on own (to be more specific) is associative array. For associative array you don’t have to specify its size. Its size keeps on increasing according to the assignment you do with any of the index.

“Dynamic” just means the size of an arrayed variable can be changed during the life of the variable. But you need some set of rules when changing the size of a dynamic array, and the LRM only gives you the ability to change the size either with the new constructor, or as the result of an assignment from an array expression having a different size.

Queues and associative arrays have the ability to change their size one element at a time.

In reply to dave_59:

I understand associative arrays change their size one element at a time but Queues can change their size with any number of elements right?

In reply to Abhyudha:

No. you can only add(push) or delete(pop) one element at a time.

When you use the array concatenation syntax, that is the same as array assignment with an expression.

q = {q,e1,e2};

Although it would be a handy optimization, the compiler is under no obligation to figure out that you are just adding two elements to the back of the queue. It just has to create queue that is two elements larger than the current queue.