首页 > 代码库 > golang的++与--
golang的++与--
http://godoc.golangtc.com/doc/faq#inc_dec
简单地说, 在golang中++,--操作是语句而不是表达式. 所以a=b++, return x++之类绝对提示错误. 语句是无法放到表达式的位置
Why are ++
and --
statements and not expressions? And why postfix, not prefix?
Without pointer arithmetic, the convenience value of pre- and postfix increment operators drops. By removing them from the expression hierarchy altogether, expression syntax is simplified and the messy issues around order of evaluation of ++
and --
(consider f(i++)
and p[i] = q[++i]
) are eliminated as well. The simplification is significant. As for postfix vs. prefix, either would work fine but the postfix version is more traditional; insistence on prefix arose with the STL, a library for a language whose name contains, ironically, a postfix increment.
golang的++与--
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。