Colobot Wiki
Advertisement

The sizeof function lets you know the number of elements contained in an array.

That is the index of the last element plus one ("empty" elements are counted).

{
	int a[12];
	a[5] = 345;
	message( sizeof(a) );  // will display 6
}

In this example we have 6 elements in the array after a[5]=345. The non initialized elements [0], [1], [2], [3] and [4] will be counted.

With multidimensional arrays you can get the size of a sub array:

float xy[][];  // 2 dimensional array
xy[5][10] = 67;
message( sizeof(xy)    );  // will display 6
message( sizeof(xy[5]) );  // will display 11
Advertisement