在Go语言中,常量的值是在编译时进行评估的。

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

Is constant value evaluated at compile time in Go?

问题

如果我有这样的代码:

const a = 1 + 1

1 + 1 是在编译时添加的吗?

英文:

If I have something like:

const a = 1 + 1

Is 1 + 1 added during the compiling time?

答案1

得分: 6

是的

> 常量表达式只能包含常量操作数,并且在编译时进行求值。

请查看常量表达式

英文:

Yes

> Constant expressions may contain only constant operands and are
> evaluated at compile time
.

Check constant expressions.

huangapple
  • 本文由 发表于 2015年12月12日 18:59:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/34239045.html
匿名

发表评论

匿名网友

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

确定