On Wed, 11 Jun 2014 02:30:00 +0000
WhatMeWorry via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
wrote:

> In Mr. Cehreli's book it says
>
> Additionally, the length of dynamic arrays can be changed by
> assigning a value to this property:
>
> int[] array; // initially empty
> array.length = 5; // now has 5 elements
>
> while in Mr. Alexandrescu's book, it says
>
> To create a dynamic array, use a new expression (§ 2.3.6.1 on
> page 51) as follows:
>
> int[] array = new int[20]; // Create an array of 20 integers
>
>
> Could someone please compare and contrast the two syntaxes. I
> presume the "new" command places the 2nd array in heap memory.

They do essentially the same thing but, the first one does it in two steps
instead of one. To better understand arrays in D, I'd advise reading this
article:

http://dlang.org/d-array-article.html

- Jonathan M Davis

Reply via email to