运算符
Go 语言没有前置的 ++ 和 — 运算符。
package operator_test
import ("fmt") // 引入代码依赖
func TestCompareArray(t *testing.T) {a := [...]int{1, 2, 3, 4}
b := [...]int{1, 3, 2, 4}
c := [...]int{1, 2, 3, 4, 5}
d := [...]int{1, 2, 3, 4}
t.Log(a == b) //false
t.Log(a == c) // 编译报错,长度不统一
t.Log(a == d) //true
}
按位清零运算符。
const (
Readable = 1 << iota
Writable
Executable
)
func TestBitClear(t *testing.T) {
a := 7 //0111
a = a &^ Readable // 革除读权限
a = a &^ Executable // 革除执行权限
t.Log(a&Readable == Readable, a&Writable == Writable, a&Executable == Executable)
}