由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - post increment
相关主题
question for C++ constant关于const_cast,地址一样,值不同?
C++ 的 问题题2
C++菜问: 怎么这样也可以?g++ default optimization error
一个诡异的const_cast问题问题: C++ static_cast between int and float
这个地址咋回事?why copy assignment operator returns non-const type?
面试问题which style do you prefer?
请教一个c++ reference问题c++环境入门问题
conversion between const to nonconst0 < -1 ? A c++ question
相关话题的讨论汇总
话题: endl话题: case话题: cout话题: supposed话题: int
进入Programming版参与讨论
1 (共1页)
r*******y
发帖数: 1081
1
I use g++ compiler. Something strange here.
case 1:
int a[3]={1, 10, 100};
int *p = a;
cout << *p++ << endl << *p < The out put is 1 1
I can not understand this. It is supposed to be 1 10, right?
case 2:
if I write it as
cout << *p++ < cout << *p < the output is 1 10 as it is supposed to be.
case 3:
Also if I have this code
int i = 1;
cout << i++ < The output is also as supposed to be, that is 1 2;
So here case 2 and case 3 are well understood. What is wrong with case 1?
Thanks.
p***o
发帖数: 1252
2
1 and 3 are undefined. Google "sequence point".

【在 r*******y 的大作中提到】
: I use g++ compiler. Something strange here.
: case 1:
: int a[3]={1, 10, 100};
: int *p = a;
: cout << *p++ << endl << *p <: The out put is 1 1
: I can not understand this. It is supposed to be 1 10, right?
: case 2:
: if I write it as
: cout << *p++ <
r*******y
发帖数: 1081
3
thanks a lot.

【在 p***o 的大作中提到】
: 1 and 3 are undefined. Google "sequence point".
f**********w
发帖数: 93
4
from the twiki "An often-cited example is the expression i=i++, which both
assigns i to itself and increments i. The final value of i is ambiguous,
because, depending on the language semantics, the increment may occur before
, after or interleaved with the assignment. The definition of a particular
language might specify one of the possible behaviors or simply say the
behavior is undefined. In C and C++, evaluating such an expression yields
undefined behavior."
Is this true? i=i++ should be expanded as i.operator=(i.operator++(int) ).
Is this behavior undefined?
1 (共1页)
进入Programming版参与讨论
相关主题
0 < -1 ? A c++ question这个地址咋回事?
What is the output of the following code?面试问题
谁给新手解释一下这个c++小程序请教一个c++ reference问题
准备面试一个java-based position,有什么书推荐一下?conversion between const to nonconst
question for C++ constant关于const_cast,地址一样,值不同?
C++ 的 问题题2
C++菜问: 怎么这样也可以?g++ default optimization error
一个诡异的const_cast问题问题: C++ static_cast between int and float
相关话题的讨论汇总
话题: endl话题: case话题: cout话题: supposed话题: int