NXC
Version 1.2.1 r5
|
NXC also support arrays.
Arrays are declared the same way as ordinary variables, but with an open and close bracket following the variable name.
To declare arrays with more than one dimension simply add more pairs of square brackets. The maximum number of dimensions supported in NXC is 4.
Arrays of up to two dimensions may be initialized at the point of declaration using the following syntax:
The elements of an array are identified by their position within the array (called an index). The first element has an index of 0, the second has index 1, and so on. For example:
You may also initialize local arrays or arrays with multiple dimensions using the ArrayInit function. The following example shows how to initialize a two-dimensional array using ArrayInit. It also demonstrates some of the supported array API functions and expressions.
NXC also supports specifying an initial size for both global and local arrays. The compiler automatically generates the required code to correctly initialize the array to zeros. If an array declaration includes both a size and a set of initial values the size is ignored in favor of the specified values.
The calls to ArrayInit are not required since we specified the initial sizes in the preceding array declarations, which means the arrays were already initialized to all zeros. In fact, the myVector array declaration is not needed unless we have a use for myVector other than initializing myArray.