Assignments

An assignment writes a variable with a value. The variable to be written is called the destination, and the value to write is called the source.

Parts

  • Destination
  • Source

In this example, the value at a is written to x.

x = a

Destination

The destination of an assignment is a variable, or an expression that results in a variable. For example, a, b[2] and c.d results in variables, but a+1 and f(x) does not.

Source

The source of an assignment is an expression that results in either a variable or a value. If the result is a variable, then the value of the variable is taken as the source.

Value copy and reference copy

When a variable of data structure type or array type is assigned, a reference is copied. When another value is assigned it is copied.