The basic assignment operator is equal ( = ), which assigns the value of its right operand to its left operand. That is, x = y assigns the value of y to x . The other assignment operators are usually shorthand for standard operations, as shown in the following
CODE/PROGRAM/EXAMPLE
package main
import "fmt"
func main() {
var a int = 5 /*Assignment operators example*/
var c int
c = a
fmt.Printf("= Operator Example, Value of c = %d\n", c )
c += a
fmt.Printf("+= Operator Example, Value of c = %d\n", c )
c -= a
fmt.Printf("-= Operator Example, Value of c = %d\n", c )
c *= a
fmt.Printf("*= Operator Example, Value of c = %d\n", c )
c /= a
fmt.Printf("/= Operator Example, Value of c = %d\n", c )
c = 200;
c <<= 2
fmt.Printf("<<= Operator Example, Value of c = %d\n", c )
c >>= 2
fmt.Printf(">>= Operator Example, Value of c = %d\n", c )
c &= 2
fmt.Printf("&= Operator Example, Value of c = %d\n", c )
c ^= 2
fmt.Printf("^= Operator Example, Value of c = %d\n", c )
c |= 2
fmt.Printf("|= Operator Example, Value of c = %d\n", c )
}
Output :
= Operator Example, Value of c = 5
+= Operator Example, Value of c = 10
-= Operator Example, Value of c = 5
*= Operator Example, Value of c = 25b
/= Operator Example, Value of c = 5
<<= Operator Example, Value of c = 800
>>= Operator Example, Value of c = 200
&= Operator Example, Value of c = 0
^= Operator Example, Value of c = 2
|= Operator Example, Value ofc = 2