Dynamic memory

Binarydepth via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 28 09:59:32 PDT 2015


On Tuesday, 28 July 2015 at 16:53:35 UTC, anonymous wrote:
> On Tuesday, 28 July 2015 at 16:41:40 UTC, Binarydepth wrote:
>> It works with 2 as input but shows error when number is 3 :(
>
>
> I can't reproduce that or I misunderstood something:
>
> $ cat a.d
> import std.stdio : readf, writef;
>  void main()	{
>  	int[2][] nam;
>  	int num;
>  	readf(" %d", &num);
>  	nam.length = num;
> 	foreach(nim; 0..num)	{
>  		readf(" %d %d", &nam[nim][0], &nam[nim][1]);
>  	}
>  	foreach(nim; 0..num)	{
>  		writef(" %d %d\n", nam[nim][0], nam[nim][1]);
>  	}
> }
> $ dmd a.d
> $ ./a
> 3
> 1 2
> 3 4
> 5 6
>  1 2
>  3 4
>  5 6

Your code works but I don't understand why this has to go 
backwards. But well I don't know how "nam.length = num;" works

My confusion comes because I declare "int[2][]" and then I use it 
backwards


More information about the Digitalmars-d-learn mailing list