Definition
An ARRAY is a fixed-size data structure that stores a sequential collection of elements of the same type in memory.
<variable> : ARRAY [<dimension>] OF <data type> := <inicialization>
|
|---|
The dimension of an ARRAY is determined by the range between the smallest and largest index, while the initialization of its elements is optional.
Example 1
The example below demonstrates the creation of an ARRAY and the assignment of one of its values to a variable.
VAR arraySrc : ARRAY[0..2] OF USINT := [11, 22, 33]; varDst : USINT; END_VAR
varDst := arraySrc[1]; |
|---|
At the end of the execution of the example code, the value of varDst should be 22.
Example 2
The example below illustrates the combination of the concepts of ARRAY, indexed variable and FOR loop to copy the values from one array to another.
VAR arraySrc : ARRAY[0..2] OF USINT := [11, 22, 33]; arrayDst : ARRAY[0..2] OF USINT; i : USINT; END_VAR
FOR i := 0 TO 2 BY 1 DO arrayDst[i] := arraySrc[i]; END_FOR |
|---|