关键字和预声明名称在Go语言中的本质区别是什么?

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

What is the essential difference between keyword and predeclare name in Go

问题

Go语言有25个关键字,比如if和switch,只能在语法允许的地方使用;它们不能用作名称。

此外,还有大约三十多个预定义的名称,比如int和true,用于内置的常量、类型和函数。

英文:

Go has 25 keywords like if and switch that may be used only where the syntax permits; they can’t be used as names.

In addition, there are about three dozen predeclared names like int and true for built-in con- stants, types, and functions

答案1

得分: 2

它们只是标识符,可以自动为您提供。

当然,您可以更改它们,因为它们只是预定义的标识符,而不是其他语言结构。

var bool int = 42
fmt.Println(bool)
// 42

https://go.dev/play/p/Mh7MF6If6oy

英文:

They are just identifiers, universally available for you automatically.

Of course, you can change them since they are just predefined identifiers, not a language construct as others.

var bool int = 42
fmt.Println(bool)
// 42

https://go.dev/play/p/Mh7MF6If6oy

huangapple
  • 本文由 发表于 2022年2月5日 08:34:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/70994366.html
匿名

发表评论

匿名网友

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

确定