Arrray sizeof

Mr. Anonymous mailnew4ster at gmail.com
Sat Dec 24 08:50:13 PST 2011


On 24.12.2011 18:46, RenatoL wrote:
> snippet:
>
>
> int[] arr1 = [1,2,3,4,5];
> int[5] arr2 = [1,2,3,4,5];
> writeln(arr1.sizeof);
> writeln(arr2.sizeof);
>
> Output:
> 8
> 20
>
> "0 is ok to me but why "8"??

8 is the size of the int[] type, which contains two pointers (or a 
pointer and a size).
To get 20, you can use:
arr1[0].sizeof * arr1.length


More information about the Digitalmars-d-learn mailing list