当前位置:网站首页>2022-08-05: What does the following go code output?A: 65, string; B: A, string; C: 65, int; D: error.

2022-08-05: What does the following go code output?A: 65, string; B: A, string; C: 65, int; D: error.

2022-08-06 07:54:36F greatly architects of the day

2022-08-05: What does the following go code output?A: 65, string; B: A, string; C: 65, int; D: error.

package mainimport ("fmt")func main() {num := 65str := string(num)fmt.Printf("%v, %T\n", str, str)}

Answer 2022-08-05:

This question can be either A or D.But the correct answer is B.However, if you check with go vet, it will prompt: conversion from int to string yields a string of one rune, not a string of digits (did you mean fmt.Sprint(x)?).
In other words, if you want to convert the number 65 into a string, you cannot use string(num). If you convert it in this way, you will get a string representation of rune, because the ASCII code of literal A is 65,So the output here is A,string.

insert image description here

原网站

版权声明
本文为[F greatly architects of the day]所创,转载请带上原文链接,感谢
https://chowdera.com/2022/218/202208060744064106.html

随机推荐