# Vector Operations

In this section, we'll discuss vector operations, which involve operations between arrays.

## Vector Operations

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.

## Operators Supporting Vector Operations

Vector operations are supported by most operators, including:

- Arithmetic Operators: +, -, *, /, %, **, ++, --
- Comparison Operators: <, >, <=, >=, ==, !=
- Logical Operators: &&, ||, !
- Assignment and Compound Assignment Operators: =, +=, -=, *=, /=, %=

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.

- Assignment Operators: "=" allows for assigning values from one array to another, resizing the destination array if necessary to match the source array's size. This operation is unique in that it can handle arrays of differing sizes by adjusting the destination array accordingly.
- Compound Assignment Operators: "+=", "-=", "*=", "/=", "%=" require that the dimensions and sizes of all array variables involved in the operation are the same, similar to arithmetic operators.

## Performing Addition with Vector 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:

c[1] = a[1] + b[1] ;

…

c[10] = a[10] + b[10] ;

という内容が代入されます。

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.

**Acknowledgement**: We greatly appreciate the cooperation of two ChatGPT AIs in translating this article!

» How we translated this article