sizeof( )

The SIZEOF() statement is used to get the size of an array or char variable. It will return either the number of elements allowed in an array, or the maximum size of a char variable.

In Querix4GL it is possible to get the size (dimension) of an array or char variable. The SIZEOF() operator takes a variable name as its argument and returns the number of elements in that variable, providing it is of type array or char. If the operator is called with any other type of variable then a zero will be returned.

An example of this operator in action follows:

DEFINE x ARRAY[10] OF CHAR(22)

The above has defined an array called ‘x’ that contains 10 elements, each of which is a 22 character char type.

DISPLAY SIZEOF(x)

Refers to the actual array and will return its size, i.e., the maximum number of elements within it, which in this case is 10.

DISPLAY SIZEOF(x[1])

The above will return 22 as this is referring to the actual element at position ‘1’ in the array ‘x’. As has been defined – each element is a 22 character char.

Now, say we have a multi-dimensional array defined as below:

DEFINE x ARRAY[10, 20] OF CHAR(22)

It is possible to discover the size of each dimension using the sizeof() function as follows:

DISPLAY SIZEOF(x)

This will return 10 as this is the size of the first dimension.

DISPLAY SIZEOF(x[2])

This will return 20 as it is referring to the size of dimension 1 (with the first dimension considered as dimension 0). Every subsequent dimension is referred to in the same way, so the next dimension in a three dimensional array would have 2 as an index and so on.

DISPLAY SIZEOF(x[1, 2])

The above will return 22 as it referring to the size of the element at position 2 in dimension 1.

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.