C ++ ++ i和i ++之间的区别

时间:2016-10-11 17:49:27

标签: c++

我想知道如果我正确地做到这一点,请告诉我,如果我是对的,如果我不能,有人会给我一个解释。谢谢。 下面的代码是什么打印的?

int n = -1;

// n increments after so now n stays at -1 now int k = 3 then n went from -1 to 0
// (increments after, adds 1)
int k = n++ * -3;

// Now n increments before execution so from the result of n++ which was 0 you increment
// before, add 1. So now n = 1 * 4 + 3 which is 7. 
cout << ++n * 4 + k;

答案是:7

我这样做的方法是否正确?

0 个答案:

没有答案
相关问题