本帖最后由 未来电子 于 2013-3-26 19:32 编辑
int p,q,i,j;
i=j=3;
q=0;
q=++j
printf("%d,",q);
这时候的运算的值是4,
int p,q,i,j;
i=j=3;
q=0;
q=(++j)+(++j);
printf("%d,",q);
这时候的运算的值是10,
int p,q,i,j;
i=j=3;
q=0;
q=(++j)+(++j)+(++j);
printf("%d,",q);
这时候的运算的值是16,
第二个结果就不明白了,会的解释一下
软件换过好几个都是这个情况。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
(WG14 N1256) C99标准,6.5-2,是我知道的关于类似问题的唯一规定:
Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. 72) Furthermore, the prior value shall be read only to determine the value to be stored. 73)
如果基于这个条款理解,q = (++j) + (++j) + (++j)由于不满足前半句的要求,因而执行完毕后的结果是Undefined,即啥结果都可能,包含表达式q的值和j的值都是不定的。C标准在这里没有保障任何东西。
当然,详细讨论这货没啥意思。。。
一周热门 更多>