3

I'm working through K&R and am presently on Exercise 1-16. It occurs to me that thus far only pre-increment has been used in the book.

Most other tutorial books and indeed source code I've seen tend to favour post-increment, except where there is an obvious affect such as in while loops etc.

Is this a stylistic or technical consideration on the part of K&R? Or do I just need to be further through the book to get my answer?!

4

3 に答える 3

1

(後置演算子の優先順位が高いため、後置インクリメント演算子が標準で最初に来る場合でも)プレインクリメントはオブジェクトの値をインクリメントする自然な方法であるため、唯一の場合に使用する正当な理由ですあなたが望むのは、オブジェクトの値をインクリメントすることです。

(++E)と同等ですが(E+=1)、そうではありません(E++)

于 2013-07-02T21:57:51.620 に答える