On 11/19/2013 03:16 PM, Carlos wrote:> Well in C I just declared an array during execution with an array with a
> multiplied variable for the size of the array.
>
> Since I only need two spaces in the array for each line of process it
> was multiplied by two.
>
> so it was like this :
>
> scanf("%d", &Num);
> int array[Num*2];

That is a VLA.

In D, you would normally use a slice. Below, 'a' and 'b' are two ways of having a slice with valid elements. On the other hand, 'c' is merely reserving space for that many elements:

import std.stdio;

void main()
{
    size_t num;
    write("How many? ");
    readf(" %s", &num);

    auto a = new int[num * 2];

    int[] b;
    b.length = num * 2;

    int[] c;
    c.reserve(num * 2);
}

Ali

Reply via email to