23 lines
803 B
Plaintext
23 lines
803 B
Plaintext
\b;Instruction \c;sizeof\n;
|
|
The sizeof function lets you know the number of elements contained in an \l;array\u cbot\array;.
|
|
That is the index of the last element plus one ("empty" elements are counted).
|
|
\c;
|
|
\s;{
|
|
\s; int a[12];
|
|
\s; a[5] = 345;
|
|
\s; message( sizeof(a) ); // will display 6
|
|
\s;}
|
|
\n;
|
|
In this example we have 6 elements in the array after \c;a[5]=345\n;. The non initialized elements \c;[0]\n;, \c;[1]\n;, \c;[2]\n;, \c;[3]\n; and \c;[4]\n; will be counted.
|
|
|
|
With multidimensionnal arrays you can get the size of a sub array:
|
|
\c;
|
|
\s;float xy[][]; // 2 dimensionnal array
|
|
\s;xy[5][10] = 67;
|
|
\s;message( sizeof(xy) ); // will display 6
|
|
\s;message( sizeof(xy[5]) ); // will display 11
|
|
\s;
|
|
\n;
|
|
\t;See also
|
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|