请帮我解决这个问题。该表达式之后的步骤是:
//Expression
offSpring1[m1++] = temp1;
//Steps:
1.- increment m1
2.- assign temp1 to offSpring
一直以为括号内的表达式是第一个做的。但是现在我很困惑。所以如果这样写:
//Expression
offSpring1[++m1] = temp1;
//Steps would be: 1.- assign temp1 to offSpring 2.- increment m1
如果步骤与第一个步骤相同,那么 i++ 和++i 之间有什么区别?
最佳答案
int i = 0;
std::cout << i++ << std::endl;
std::cout << i << "\nreset" << std::endl;
i = 0;
std::cout << ++i << std::endl;
std::cout << i << std::endl;
输出:
0
1
reset
1
1
i++
返回表达式中当前的值,然后递增变量。
++i
将递增变量,然后返回要在当前表达式中使用的值。
关于c++ - 增量、前增量和后增量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9298020/