使用++ i,i ++ [英] use of ++i, i++

查看:79
本文介绍了使用++ i,i ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



从阅读一些指南我明白了前缀,后缀操作

这样,前者立即执行增量,后者执行
$

语句紧接着结束后的b $ b增量。这是正确的吗?


如果我遵守该规则,以下两个陈述是等价的


for(i = 0; i< 1; i ++)

printf(为i打印的第一个值是%d,i);


for(i = 0; i< ; 1; ++ i)

printf(为i打印的第一个值是%d,i);


此处的输出相同因为上面的printf(...)语句是在''增量

运算符'后面的第一个语句结束后紧跟




提前致谢。


新手。

解决方案

"新手" < TE ************ @ yahoo.com>写道:

从阅读一些指南我明白了前缀,后缀操作这样,前者立即执行增量,后者立即执行增量后的增量
声明紧接着结束之后。那是对的吗 ?


实际上,增量发生时未指定(除了
,它发生在前一个和下一个序列点之间)。

实际差异是前缀增量运算符

产生修改后的值,而后缀增量运算符

产生原始值。

如果我按照这个规则,下面的两个陈述是等价的(i = 0; i< 1; i ++)
printf(为i打印的第一个值是%d) ,i);

for(i = 0; i< 1; ++ i)
printf(为i打印的第一个值是%d,i);




是的,这些是等价的。 (我想在我自己的新行中输入
printf输出,但我不会使用1迭代循环。)

-

char a [] =" \ n .CJacehknorstu" ;; int putchar(int); int main(void){unsigned long b []

= {0x67dffdff,0x9aa9aa6a,0xa77ffda9, 0x7da6aa6a,0xa6 7f6aaa,0xaa9aa9f6,0x1f6},* p =

b,x,i = 24; for(; p + =!* p; * p / = 4)switch(x = * p& 3)案例0:{return 0; for(p - ; i - ; i - )case

2:{i ++; if(1)break; else default:continue; if(if 0)案例1:putchar(a [i& 15]); break;}}}


On 27/2/05 6:28 AM,Greenhorn写道:< blockquote class =post_quotes> hi,
从阅读一些指南我明白了前缀,后缀操作这样,前者立即执行增量,后者执行后立即增加
增量
声明紧接着结束。这是正确的吗?

如果按照这个规则,下面的两个陈述是等价的(i = 0; i< 1; i ++)
printf(为i打印的第一个值是%d,i);

for(i = 0; i< 1; ++ i)
printf(&为i打印的第一个值是%d,i);




是的,但考虑一下:


int a = ++ i;

int b = i ++;


还要考虑当我不是整数时会发生什么。我可以是给定课程的任何

,它可以做任何事情。




" ;新手" < TE ************ @ yahoo.com>在消息中写道

news:11 ********************** @ g14g2000cwa.googlegr oups.com ...


从阅读一些指南我理解前缀,后缀操作这样,前者立即执行增量,后者在紧随其后立即执行增量后结束
声明。这是正确的吗?

如果按照这个规则,下面的两个陈述是等价的(i = 0; i< 1; i ++)
printf(为i打印的第一个值是%d,i);

for(i = 0; i< 1; ++ i)
printf(&为i打印的第一个值是%d,i);

这里的输出与上面的printf(...)语句相同,是紧跟在第一个语句结束后的
''增加
运营商''

提前致谢。

greenhorn。



"立即数传递给我的价值就是你所说的。 --i,传递

i,as(i0-1),其中i--传递i,如i0;


将您的代码更改为:< ($ = 0; i< 1; printf(" i为i打印的第一个值是%d,i ++));


for(i = 0; i< 1; printf(为i打印的第一个值是%d,++ i));


看到差异。


hi,
From reading some guides i understood that prefix, postfix operate
this way, former executes the increment right away, latter executes the
increment after the immediately after the immediately following end of
statement. Is that correct ?

If i go by that rule, the below two statements are equivalent

for(i=0;i < 1;i++)
printf("The first value printed for i is %d", i);

for(i=0;i < 1;++i)
printf("The first value printed for i is %d", i);

The outputs are same here as printf(...) statement above is the
immediately following end of the first statement after the ''increment
operator(s)''

Thanks in advance.

greenhorn.

解决方案

"Greenhorn" <te************@yahoo.com> writes:

From reading some guides i understood that prefix, postfix operate
this way, former executes the increment right away, latter executes the
increment after the immediately after the immediately following end of
statement. Is that correct ?
Actually, it is unspecified when the increment occurs (except
that it occurs between the previous and next sequence point).
The actual difference is that the prefix increment operator
yields the modified value whereas the postfix increment operator
yields the original value.
If i go by that rule, the below two statements are equivalent

for(i=0;i < 1;i++)
printf("The first value printed for i is %d", i);

for(i=0;i < 1;++i)
printf("The first value printed for i is %d", i);



Yes, these are equivalent. (I would want a new-line in my own
printf output though, and I would not use a 1-iteration loop.)
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa6 7f6aaa,0xaa9aa9f6,0x1f6},*p=
b,x,i=24;for(;p+=!*p;*p/=4)switch(x=*p&3)case 0:{return 0;for(p--;i--;i--)case
2:{i++;if(1)break;else default:continue;if(0)case 1:putchar(a[i&15]);break;}}}


On 27/2/05 6:28 AM, Greenhorn wrote:

hi,
From reading some guides i understood that prefix, postfix operate
this way, former executes the increment right away, latter executes the
increment after the immediately after the immediately following end of
statement. Is that correct ?

If i go by that rule, the below two statements are equivalent

for(i=0;i < 1;i++)
printf("The first value printed for i is %d", i);

for(i=0;i < 1;++i)
printf("The first value printed for i is %d", i);



Yes, but consider this:

int a = ++i;
int b = i++;

And also consider what happens when i is not an integer. i can be any
given class, which might do anything at all.



"Greenhorn" <te************@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

hi,
From reading some guides i understood that prefix, postfix operate
this way, former executes the increment right away, latter executes the
increment after the immediately after the immediately following end of
statement. Is that correct ?

If i go by that rule, the below two statements are equivalent

for(i=0;i < 1;i++)
printf("The first value printed for i is %d", i);

for(i=0;i < 1;++i)
printf("The first value printed for i is %d", i);

The outputs are same here as printf(...) statement above is the
immediately following end of the first statement after the ''increment
operator(s)''

Thanks in advance.

greenhorn.


The "immediate" value passed for i is what your talking about. --i, passes
i, as (i0-1), where i--, passes i, as i0;

change your code to :

for(i=0;i < 1; printf("The first value printed for i is %d", i++) );

for(i=0;i < 1; printf("The first value printed for i is %d", ++i));

to see the difference.


这篇关于使用++ i,i ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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