关于Go语言的几个问题

huangapple go评论85阅读模式
英文:

A few questions about the Go Language

问题

我对Go编程语言有几个问题:

  1. 在该语言中,整数和浮点数变量的相加是如何实现的?
  2. 最后一个问题和整数和浮点数字面值的相加(例如3+2.1)有什么区别吗?
  3. Go语言中有哪些序列器?
英文:

I have a few questions about the Go programming language:

  1. How is the addition of int and float variables implemented in the language?
  2. is there a diffrence between the last question and the addition of int and float literals (for instance 3+2.1)?
  3. 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

  1. 没有隐式类型转换;您需要明确决定您想要哪种类型的加法,并将一个或两个操作数转换为相关类型。

  2. 您可以通过简单的实验来回答这个问题。

     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,代码将无法编译。

  3. 您所说的“sequencers”是什么意思?

英文:
  1. 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.

  2. 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.

  3. What do you mean by 'sequencers'?

答案3

得分: 0

经过仔细检查和同事的帮助,我找到了第三个问题的答案:
序列控制器是一种改变正常控制流的构造。
特别是在Go语言中,序列控制器包括:

  1. goto
  2. Break
  3. continue
  4. return
  5. fallthrough
  6. go
  7. defer
  8. 以及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:

  1. goto
  2. Break
  3. continue
  4. return
  5. fallthrough
  6. go
  7. defer
  8. and panic (exception).
    Thanks all for the help.

huangapple
  • 本文由 发表于 2011年1月9日 01:37:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/4635202.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定