In this section, we'll discuss vector operations, which involve operations between arrays.
VCSSL supports vector operations, enabling the same operation to be applied uniformly across all elements of operand arrays.
To perform vector operations, excluding the plain assignment operation "=", it's generally required that the dimensions and sizes of all array variables in the expression are the same. Additionally, non-array variables can be included in expressions, and in such cases, they are treated as if they were arrays storing the same value for all elements.
Vector operations are supported by most operators, including:
These operators automatically engage in vector operations whenever the operands (*) are arrays.
There is difference between size restrictions of assignment operations and compound assignment operations.
Let's actually perform addition using vector operations:
- Execution Result -
When executed, it displays 30. Let's break down the process since it's a bit lengthy.
First, arrays "a" and "b" with 11 elements each are initialized. a is assigned the square of integers from 0 to 10, and b is assigned integers from 0 to 10 directly. Then, an array c with 11 elements is created.
Next, the line "c = a + b" executes vector addition. This operation assigns the following values to c:
という内容が代入されます。
Finally, the function to print c[5] is called, and the program ends.
For c[5], it contains a[5] + b[5], which is 25 + 5, hence the output value of 30 as expected. This confirms that vector addition was successfully performed.