位运算内容很多的,位运算可以判断奇偶,数值交换等
package main
func main() {
var a, b = 611, 193
//A = 110
a = a ^ b
b = a ^ b
a = a ^ b
println(a, b)
}
package main
func main() {
var a, b = 611, 193
//A = 110
a = a ^ b
b = a ^ b
a = a ^ b
println(a, b)
}
2018-04-29
iota前面的常量必须先赋值,如下面是错误的:
package main
import (
"fmt"
)
const (
a
b = iota
c
)
func main() {
fmt.Println(a, b, c)
}
package main
import (
"fmt"
)
const (
a
b = iota
c
)
func main() {
fmt.Println(a, b, c)
}
2018-04-29
能解释一下求len和unsafe.Sizeo的区别么
==================================
package main
import (
"fmt"
"unsafe"
)
func main() {
const a = 1
const b = "你好go"
//fmt.Println(len(a))
fmt.Println(unsafe.Sizeof(a))
fmt.Println(len(b))
fmt.Println(unsafe.Sizeof(b))
}
==================================
package main
import (
"fmt"
"unsafe"
)
func main() {
const a = 1
const b = "你好go"
//fmt.Println(len(a))
fmt.Println(unsafe.Sizeof(a))
fmt.Println(len(b))
fmt.Println(unsafe.Sizeof(b))
}
2018-04-29
go是utf8编码,中文和特殊字符可以作为变量,那中文怎么区分大小写呢?
======================
package b
var Foo int = 1
var π int = 2
var Π int = 3
var 中 int = 4
===========================
package main
import (
"b"
"fmt"
)
func main() {
fmt.Println(b.Foo)
fmt.Println(b.Π)
//fmt.Println(b.π)
//fmt.Println(b.中)
}
======================
package b
var Foo int = 1
var π int = 2
var Π int = 3
var 中 int = 4
===========================
package main
import (
"b"
"fmt"
)
func main() {
fmt.Println(b.Foo)
fmt.Println(b.Π)
//fmt.Println(b.π)
//fmt.Println(b.中)
}
2018-04-29