这是来自 kn king 的 c 编程的问题:一种现代方法。我无法理解他给出的解决方案:-
The expression ++i is equivalent to (i += 1). The value of both expressions is i after
the increment has been performed.
我怎么理解这个?
最佳答案
i = 10
printf("%d", i++);
将打印 10,其中 as
printf("%d", ++i);
将打印 11
X = i++
可以这样想
X = i
i = i + 1
X =++i
是
i = i + 1
X = i
所以,
printf ("%d", ++i);
与
相同printf ("%d", i += 1);
但不是
printf ("%d", i++);
虽然在这三个语句中的任何一个之后 i
的值都是相同的。
关于c - 从任何角度来看,++i 和 i+=1 之间有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18420479/