作业帮 > 综合 > 作业

int a=3;cout

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/10/06 22:07:16
int a=3;cout
因为两次操作都是未定义的,所以结果也是未定义的,标准不保证结果的标准性,或者说准确性,在我曾经写过的一篇文章中曾经听到过另一个类似的例子
为什么a+=a-=b*=c a=1 b=2 c=3的结果是未定义的?
因为按照标准,在一个表达式中,一个对象只能有最多一次的存储修改.
同样,例如i=i++;i=++i;之类的也是未定义操作.
注:未定义操作不等于操作会让编译器报错或者得不到结果,而是这个操作的结果是由编译器或者其他其他情况的,标准并不保证这种操作的唯一性.
原文:Between the previous and next sequence point an object shall have its stored value
modified at most once by the evaluation of an expression. Furthermore, the prior value
shall be read only to determine the value to be stored.70)
70) This paragraph renders undefined statement expressions such as
i = ++i + 1;
a[i++] = i;
while allowing
i = i + 1;
a[i] = i;
ISO_IEC_9899_C_1999 67页 §6.5
再问: 那写成int a=3,b,c,d;cout