Operator sizeof

Many functions are using sizeof operator as one of the default values.

The nice thing is that as in AdjArray() or PrintArray(), the size of the array arr is given at run time. And this value is usually used as a boundary inside the function. So, if it is really not needed, always leave this param out of the function and it will be passed correctly for you.

// Function definition
AdjArray(arr[], pintensity, startindex = 0, count = sizeof arr, size = sizeof arr)
{
    ...
}

or

PrintArray(arr[],size=sizeof arr)
{
    ....
}

//usage:

new cells[20]=[1,2,...]                          //this populates the array by 1,2,3,4,5,....
PrintArray(cells)
....
(  0) 00000001 00000002 00000003 00000004         ................
(  4) 00000005 00000006 00000007 00000008         ................
(  8) 00000009 0000000A 0000000B 0000000C         ................
( 12) 0000000D 0000000E 0000000F 00000010         ................
( 16) 00000011 00000012 00000013 00000014         ................

NOTE: Sizeof packed strings or packed arrays won't give the number of elements, but always the number of cells! See more at Packed and unpacked

A few more examples:

Note: "sizeof" can be used either with braces or without, i.e. sizeof(msg) is equal to sizeof msg.

Last updated