英文:
A few questions about the Go Language
问题
我对Go编程语言有几个问题:
- 在该语言中,整数和浮点数变量的相加是如何实现的?
- 最后一个问题和整数和浮点数字面值的相加(例如3+2.1)有什么区别吗?
- Go语言中有哪些序列器?
英文:
I have a few questions about the Go programming language:
- How is the addition of int and float variables implemented in the language?
- is there a diffrence between the last question and the addition of int and float literals (for instance 3+2.1)?
- What are all the sequencers in the Go language?
答案1
得分: 4
关于你的问题的答案,请阅读Go编程语言规范。
例如,对于前两个问题,请先阅读数值类型、算术运算符和类型转换的部分。
英文:
For the answers to your questions read The Go Programming Language Specification.
For example, for the first two questions start by reading the sections on Numeric types, Arithmetic operators, and Conversions.
For the third question, start by reading the Statements sections and the section on Handling panics.
答案2
得分: 3
-
没有隐式类型转换;您需要明确决定您想要哪种类型的加法,并将一个或两个操作数转换为相关类型。
-
您可以通过简单的实验来回答这个问题。
package main import "fmt" func main() { var i int = 3 + 2 var f float = 3 + 2.1 fmt.Printf("%d %f\n", i, f) }
如果您尝试用2.1替换2,代码将无法编译。
-
您所说的“sequencers”是什么意思?
英文:
-
There aren't implicit type conversions; you will have to explicitly decide which sort of addition you want and convert one or both operands to the relevant type.
-
You could answer this by simple experimentation.
package main import "fmt" func main() { var i int = 3 + 2 var f float = 3 + 2.1 fmt.Printf("%d %f\n", i, f) }
If you try replacing the 2 with 2.1, the code does not compile.
-
What do you mean by 'sequencers'?
答案3
得分: 0
经过仔细检查和同事的帮助,我找到了第三个问题的答案:
序列控制器是一种改变正常控制流的构造。
特别是在Go语言中,序列控制器包括:
- goto
- Break
- continue
- return
- fallthrough
- go
- defer
- 以及panic(异常)。
感谢大家的帮助。
英文:
After close examination and help from colleagues I found an answer to the third question:
Sequencers are a construct that varies the normal flow of control.
particularly in go the sequencers are:
- goto
- Break
- continue
- return
- fallthrough
- go
- defer
- and panic (exception).
Thanks all for the help.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论