colobot-data/help/cbot/R/sizeof.txt

23 lines
1.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

\b;Инструкция \c;sizeof\n;
Фунция sizeof позволяет узнать количестов элементов. содержащихся в \l;массиве\u cbot\array;.
Т.е. индекс последнего элемента +1 ("пустые" элементы тоже считаются).
\c;
\s;{
\s; int a[12];
\s; a[5] = 345;
\s; message( sizeof(a) ); // will display 6
\s;}
\n;
В этом примере у нас есть 6 элементов в массиве после \c;a[5]=345\n;. Не инициализированные элементы - \c;[0]\n;, \c;[1]\n;, \c;[2]\n;, \c;[3]\n; и \c;[4]\n; будут посчитаны.
С многомерными массивами вы можете получить размер суб массива:
\c;
\s;float xy[][]; // 2 одномерных массива
\s;xy[5][10] = 67;
\s;message( sizeof(xy) ); // выведем 6
\s;message( sizeof(xy[5]) ); // выведем 11
\s;
\n;
\t;См. также
\l;Инструкции\u cbot;, \l;типы\u cbot\type; и \l;категории\u cbot\category;.