下面是我查询的代码:
我有一个单维数组 a
当我打印 a[0][0]
时,我不明白为什么它返回字符 a
的 ascii 值:
package main
import (
"fmt"
)
func main() {
a := [3]string{"a","b","c"}
fmt.Println(a[0][0])
}
输出:97
最佳答案
下面是如何打印ascii的代码示例
a := [3]string{"a","b","c"}
for _, rune := range a {
fmt.Println(rune)// It will print a,b,c
}
因为你在你的代码中使用了[0][0],所以它是等价的
for _, rune := range a {
fmt.Println(rune[0])// It will print 97,98,99
// rune is equal to x := 'a'
// when you write it like x := 'a' and
// fmt.Println(x) the output is 97
}
关于arrays - 戈朗 : Could not understand how below code is executing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48264416/