Help with ArraySize

 

Hi,

I know this is quite basic, but I have a doubt on ArraySize function; does it return the size of the array or the number of non-null elements in the array?

For example:

double array[];

ArrayResize(array,100);

array[0]=4;

array[1]=4;

array[2]=4;

int size=ArraySize[array];


In this case, will ArraySize function return a value of 3 (number of non-null elements), or a value of 100 (the actual size of the array)?

Many thanks!

 
Why don't you try and see?
 
toshiorusso86:

Hi,

I know this is quite basic, but I have a doubt on ArraySize function; does it return the size of the array or the number of non-null elements in the array?

For example:

double array[];

ArrayResize(array,100);

array[0]=4;

array[1]=4;

array[2]=4;

int size=ArraySize[array];


In this case, will ArraySize function return a value of 3 (number of non-null elements), or a value of 100 (the actual size of the array)?

Many thanks!

A simple test will give you the answer. It returns the number of elements.

Be aware that with multi dimension arrays it will return the total elements for all dimensions. In this case if you want the number of elements in a dimension, you must use ArrayRange()

 

Will test it :) Many thanks for the help and additional info

So I assume it will return 100 in this case...do you know how I could get to the number of non-null elements in the array?

Thanks!

 
Try to print an uninitialized element.
Elements that are not initialized get the value 0.
So you can't know which elements are not initialized, if 0 is a legitimate value in the array.
 
Amir Yacoby:
Try to print an uninitialized element.
Elements that are not initialized get the value 0.
So you can't know which elements are not initialized, if 0 is a legitimate value in the array.
I tested it and I get your point, I will try with a for loop then
Reason: