golang逻辑运算

短路或与短路与

a == b ||  a == c
 
 若是a等于b,就不会检测a是否等于c,直接返回true
 
 同理
 a == b && a == c
 若是a不等于b,也不会检测a是否等于c,直接返回false

除运算

- 1
fmt.Println("9 / 4:",9/4)
fmt.Println("9.0 / 4:",9.0/4)

9 / 4: 2
9.0 / 4: 2.25

-2 
不使用中间变量交换两个变量
a = a + b
b = a - b
a = a - b

-3
数组中存在一个单独值,其余都是成对的,怎么找到

arr := []int {1,1,2,2,3,3,4}
temp := 0
for _,v := range arr {
    temp ^= v
}
fmt.Println("temp:",temp)

temp: 4
相关文章
相关标签/搜索