Assignment

Assignments are used to assign the value of a variable or statement to that of another variable or statement. Assignments also allow some shortcuts; see the example below.

// assignment shortcut
void main()
{
     string sExample = "This is an ";
     sExample += "example";
     // functionally equivalent to typing
     // sExample = sExample + "example";
}
Arithmatic Assignments (perform assignments on int and float data types)

Symbol Operation Description
= Assignment Assigns the value of an expression to a variable.
+= Assignment Addition Assigns the value of the variable being assigned to incremented by a number.
/= Assignment Division Assigns the value of the variable being assigned to divided by a number.
%= Assignment Modulo Assigns the value of the variable being assigned to modulo by a number.
*= Assignment Mulitplication Assigns the value of the variable being assigned to multiplied by a number.
-= Assignment Subtraction Assigns the value of the variable being assigned to subtracted by a number.

String Assignments (perform assignments on string data type)

Symbol Operation Description
= Assignment Assigns the value of an expression to a string variable.
+= Assignment Concatentation Assigns the value of the variable being assigned concatenated with an expression.

Bitwise Assignments (perform assignments on int data type)

Symbol Operation Description
|= OR Assignment Assigns the value of the variable being assigned bitwise OR'd with an expression.
&= AND Assignment Assigns the value of the variable being assigned bitwise AND'd with an expression.
^= XOR (exclusive OR) Assignment Assigns the value of the variable being assigned bitwise XOR'd with an expression.
<<= Shift Left Assignment Assigns the value of the variable being assigned shifted left (multiple) by an expression.
>>= Shift Right Assignment Assigns the value of the variable being assigned shifted right (divided) by an expression.
>>>= Shift Right Zero Fill Assignment Assigns the value of the variable being assigned shifted right (divided) by an expression, but discarding values shifted off the right side of the resulting value and padding the left side with zeros ("0").




 author: Charles Feduke, additional contributor(s): Ryan Hunt