Operators/Assignment

From FizzFuzz

Jump to: navigation, search
Go back to Operators.

Assignment is an operation that stores the value of one variable, literal, or value in another variable, replacing whatever value was there before. The operator is binary and infix, as well as non-commutative and non-associative. The operator is = (an equals sign).

Contents

Notation

α = β

Where α is a variable and β is a variable, literal, or other value. If αtypeβtype, then β will be coerced to αtype. The result is dependent on the types of α and β.

Compound Assignment

A number of operations support compound assignment. This is an assignment in the form of α #= β, where # is the operator. It is the case of the following:

α #= β
α = α # β

It effectively serves as short-hand notation. The following operations allow this form:

Example

int alpha = 1;
int beta = 2;
float gamma = 3.5;
 
output << alpha; // Outputs "1".
 
alpha = beta;
output << alpha; // Outputs "2".
 
alpha = gamma;
output << alpha; // Outputs "3", as gamma is coerced to an int, and loses
                 // the precision of its decimal point.

See Also