关于* =(和类似)运算符的问题 [英] Question about the *= (and similar) operator

查看:83
本文介绍了关于* =(和类似)运算符的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在陈述a * =表达中假设表达式是

括号?例如,如果我写a * = b + c,这是相同的

为a = a *(b + c)或a = a * b + c或?

In the statement "a *= expression" is expression assumed to be
parenthesized ? For example if I write "a *= b+c" is this the same
as "a = a * (b+c)" or "a = a * b+c" ?

推荐答案

sp **** @ gmail.com 写道:
sp****@gmail.com writes:
在语句a * = expression中表达式假设是括号括起来的吗?例如,如果我写a * = b + c,这与a = a *(b + c)相同吗?或a = a * b + c或?
In the statement "a *= expression" is expression assumed to be
parenthesized ? For example if I write "a *= b+c" is this the same
as "a = a * (b+c)" or "a = a * b+c" ?




写一个小C程序试试吧。

学习会带来好处。


-

Chris。



Write a small C program and try it.
The learning will provide benefits.

--
Chris.




Chris McDonald写道:

Chris McDonald wrote:
sp****@gmail.com 写道:
sp****@gmail.com writes:
在陈述a * =表达表达式假设是括号括起来的吗?例如,如果我写a * = b + c,这与a = a *(b + c)相同吗?或a = a * b + c或?
In the statement "a *= expression" is expression assumed to be
parenthesized ? For example if I write "a *= b+c" is this the same
as "a = a * (b+c)" or "a = a * b+c" ?



写一个小C程序并试一试。
学习会带来好处。



Write a small C program and try it.
The learning will provide benefits.




它不会我不会提供任何更多的好处,而是来自

a的回复。加上实验是一种危险的学习方法,除非事先知道调查的行为是b $ b b b是由标准决定的。如果情况并非如此,那么人们就不会知道他观察到的是标准的还是实现的定义,或者是否定义了未定义的,这些恰好恰好在特定的情况下工作特定平台上特定的
编译器。据我所知,表达式

是否是b * bb括号括号还是a * =表达式 ,是实现定义



如果想要实现可移植性,应该在

中包括括号

代码每当标准操作符优先没有给出

期望

结果。


Spiros Bousbouras



It wouldn''t provide any more benefits than what I would get from
a reply here. Plus experiments are a dangerous way of learning
about C unless one knows beforehand that the behaviour being
investigated
is determined by the standard. If that''s not the case then one will not
know if what he observes is standard or implementation defined or
undefined which just happened to work in a specific way under a
specific
compiler on a specific platform. For all I know , whether "expression"
is
parenthesized or not in "a *= expression" , is implementation defined
and
if one wants to achieve portability one should include parentheses in
the
code whenever the standard operator precedence does not give the
desired
result.

Spiros Bousbouras


sp****@gmail.com 写道:
在声明中a * =表达式表达式假设是括号括起来的吗?例如,如果我写a * = b + c,这与a = a *(b + c)相同吗?或a = a * b + c或?
In the statement "a *= expression" is expression assumed to be
parenthesized ? For example if I write "a *= b+c" is this the same
as "a = a * (b+c)" or "a = a * b+c" ?




ISO C99草案(N1124)§6.5.16.2:

E1 op = E2形式的复合赋值不同于简单

赋值表达式E1 = E1 op(E2)只是因为左值E1是

只评估一次。

-

一个人的自由停止在别人'开始的地方

Giannis Papadopoulos

计算机和通信工程部。 (CCED)

塞萨利大学
http:// dop .freegr.net /


这篇关于关于* =(和类似)运算符的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆