Professional Documents
Culture Documents
Contents
• 1Semantics
• 2Single assignment
• 3Value of an assignment
• 4Variant forms of assignment
o 4.1Augmented assignment
o 4.2Chained assignment
o 4.3Parallel assignment
• 5Assignment versus equality
• 6Notation
• 7See also
• 8Notes
• 9References
Semantics[edit]
An assignment operation is a process in imperative programming in which different
values are associated with a particular variable name as time passes. [1] The program,
in such model, operates by changing its state using successive assignment
statements.[2][3] Primitives of imperative programming languages rely on assignment
to do iteration.[4] At the lowest level, assignment is implemented using machine
operations such as MOVE or STORE .[2][4]
Variables are containers for values. It is possible to put a value into a variable and
later replace it with a new one. An assignment operation modifies the current state of
the executing program.[3] Consequently, assignment is dependent on the concept
of variables. In an assignment:
int x = 10;
float y;
x = 23;
y = 32.4f;
In this sample, the variable x is first declared as an int, and is then assigned the
value of 10. Notice that the declaration and assignment occur in the same statement.
In the second line, y is declared without an assignment. In the third line, x is
reassigned the value of 23. Finally, y is assigned the value of 32.4.
For an assignment operation, it is necessary that the value of the expression is well-
defined (it is a valid rvalue) and that the variable represents a modifiable entity (it is
a valid modifiable (non-const) lvalue). In some languages, typically dynamic ones, it
is not necessary to declare a variable prior to assigning it a value. In such
languages, a variable is automatically declared the first time it is assigned to, with
the scope it is declared in varying by language.