i ++和++ i [英] i++ and ++i

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

问题描述

我知道其中一个是有效率的。但是不知道他们中的哪一个。

有人可以解释我哪一个有效且为什么?


提前致谢。

解决方案



jsshah写道:


我知道其中一个是有效的。



然后你就知道错了。两者(或两者都没有)是有效的。


但是不知道他们中的哪一个。

有人可以解释我哪一个他们是有效的,为什么?



不。没有人可以向你解释哪一个是有效的。


毫无疑问,有人会向你解释你为什么要问一个

废话(wrt C) ) 题。我希望你能回答他们的答案。


-

Lew Pitcher


Lew Pitcher< lp ****** @ sympatico.cawrote:


(WRT ++ i vs. i ++正在高效)


然后你就知道错了。两者(或两者都没有)是有效的。


毫无疑问,有人会向你解释为什么你要问一个

无意义(wrt C)的问题。我希望你能回答他们的答案。



我认为这对OP来说是不必要的苛刻,他似乎只是简单地忽略了更多这个词。在他或她的查询中。我认为

这取决于你的实施答案可能更合适,或者至少更有帮助和更有用。然后再次获得
,或许是STFW。答案本来是理想的,那就是

讽刺和潜在的帮助。


-

C. Benson Manica |我*应该*知道我在说什么 - 如果我

cbmanica(at)gmail.com |不,我需要知道。火焰欢迎。




jsshah写道:


我知道其中一个他们很有效率。但是不知道他们中的哪一个。

有人能解释我哪一个是有效的,为什么?



我认为一个实现可以比另一个更有效地执行一个表单

。您需要查看两种情况下的汇编程序

输出。有人可能认为它可以*更容易使编译器为++ i生成比i ++更少的指令,但如果现代编译器无法生成,我将会感到惊讶在这两种情况下都不会发现任何成语并且做了两个聪明的事情。

-

- Mark


I know that one of them is efficient. But dont know which one of them.
Can someone explain me which one of them is efficient and why?

Thanks in advance.

解决方案


jsshah wrote:

I know that one of them is efficient.

Then you know wrong. Neither (or both, for that matter) are effecient.

But dont know which one of them.
Can someone explain me which one of them is efficient and why?

Nope. No one can explain to you which one is effecient.

Someone here will, no doubt, explain to you why you have asked a
nonsense (wrt C) question. I hope you read their answer.

--
Lew Pitcher


Lew Pitcher <lp******@sympatico.cawrote:

(WRT ++i vs. i++ being "efficient")

Then you know wrong. Neither (or both, for that matter) are effecient.

Someone here will, no doubt, explain to you why you have asked a
nonsense (wrt C) question. I hope you read their answer.

I think this is unnecessarily harsh on OP, who seems to have simply
neglected to include the word "more" in his or her query. I think the
"it depends on your implementation" answer would have been more
appropriate, or at the least more helpful and informative. Then
again, perhaps the "STFW" answer would have been ideal, that is both
snarky and potentially helpful.

--
C. Benson Manica | I *should* know what I''m talking about - if I
cbmanica(at)gmail.com | don''t, I need to know. Flames welcome.



jsshah wrote:

I know that one of them is efficient. But dont know which one of them.
Can someone explain me which one of them is efficient and why?

I suppose it''s possible for an implementation to execute one form more
efficiently than the other. You would need to look at the assembler
output for the two cases. One might image that it *could* be easier for
the compiler to generate fewer instructions for ++i than i++ but I''d be
surprised if modern compilers couldn''t detect either idiom and do the
smart thing in both cases.
--
- Mark


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

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