Help with ArraySize

To add comments, please log in or register
toshiorusso86
23
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!

Amir Yacoby
1188
Amir Yacoby  
Why don't you try and see?
Keith Watford
Moderator
13294
Keith Watford  
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()

toshiorusso86
23
toshiorusso86  

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!

Amir Yacoby
1188
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.
toshiorusso86
23
toshiorusso86  
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
To add comments, please log in or register