算术运算符
+ - * / % ++ --
不支持前置++ 和前置--
比较运算符
== != > < >= <=
用==比较数组
- 相同维数且含有相同个数元素的数组才可以比较
- 每个元素都相等的才相等
数组是引用类型
长度不同的数组比较时会出现编译错误a == b (mismatched types [5]int and [6]int)
逻辑运算符
&& || !
位运算符
& | ^ << >>
按位置零运算符&^
1 &^0 -- 1
1 &^1 -- 0
0 &^1 -- 0
0 &^0 -- 0
右边是1则置零,结果总是0;右边是0,原来左边是什么还是什么
package operator_test
import "testing"
const (
Readable = 1 << iota
Writable
Executable
)
func TestCompareArrays(t *testing.T) {
a := [...]int{1,2,3,4,5}
//b := [...]int{1,2,3,4,5,6}
c := [...]int{1,2,3,5,5}
d := [...]int{1,2,3,4,5}
//t.Log(a == b)
t.Log(a == c)
t.Log(a == d)
}
func TestBitClear(t *testing.T) {
a := 7//0111
a = a &^Executable
a = a &^Readable
t.Log(a & Readable == Readable,a & Writable == Writable, a & Executable == Executable)
}
网友评论