arrays - 戈朗 : Could not understand how below code is executing

标签 arrays go

下面是我查询的代码: 我有一个单维数组 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/

相关文章:

javascript - 将构造函数传递给 Array.map?

Python:2 暗淡形状的数组 (1,1024) 被读取为 3 暗淡数组

parsing - 使用 sub 方法进行日期解析

http - 去重试 403 禁止的 http 请求?

gob panic 解码接口(interface)

unit-testing - 如何在 Golang 中正确模拟具有成员函数的结构?

go - 自定义事务处理器未收到请求

arrays - 使用特定条件在一行中查找重复值

c - 定义 C 函数数组

arrays - 在 Play2 和 Scala 中解析没有数据类型的 JSON