# D語言賦值運算符

=

C = A + B will assign value of A + B into C

+=

C += A is equivalent to C = C + A

-=

C -= A is equivalent to C = C - A

*=

C *= A is equivalent to C = C * A

/=

C /= A is equivalent to C = C / A

%=

C %= A is equivalent to C = C % A

<<=

C <<= 2 is same as C = C << 2

>>=

C >>= 2 is same as C = C >> 2

&=

C &= 2 is same as C = C & 2

^=

C ^= 2 is same as C = C ^ 2

|=

OR運算和賦值運算符

C |= 2 is same as C = C | 2

## 示例

import std.stdio; int main(string[] args) { int a = 21; int c ; c = a; writefln("Line 1 - = Operator Example, Value of c = %d
", c ); c += a; writefln("Line 2 - += Operator Example, Value of c = %d
", c ); c -= a; writefln("Line 3 - -= Operator Example, Value of c = %d
", c ); c *= a; writefln("Line 4 - *= Operator Example, Value of c = %d
", c ); c /= a; writefln("Line 5 - /= Operator Example, Value of c = %d
", c ); c = 200; c = c % a; writefln("Line 6 - %s= Operator Example, Value of c = %d
",'x25', c ); c <<= 2; writefln("Line 7 - <<= Operator Example, Value of c = %d
", c ); c >>= 2; writefln("Line 8 - >>= Operator Example, Value of c = %d
", c ); c &= 2; writefln("Line 9 - &= Operator Example, Value of c = %d
", c ); c ^= 2; writefln("Line 10 - ^= Operator Example, Value of c = %d
", c ); c |= 2; writefln("Line 11 - |= Operator Example, Value of c = %d
", c ); return 0; }

Line 1 - = Operator Example, Value of c = 21

Line 2 - += Operator Example, Value of c = 42

Line 3 - -= Operator Example, Value of c = 21

Line 4 - *= Operator Example, Value of c = 441

Line 5 - /= Operator Example, Value of c = 21

Line 6 - %= Operator Example, Value of c = 11

Line 7 - <<= Operator Example, Value of c = 44

Line 8 - >>= Operator Example, Value of c = 11

Line 9 - &= Operator Example, Value of c = 2

Line 10 - ^= Operator Example, Value of c = 0

Line 11 - |= Operator Example, Value of c = 2