#include <iostream>
using namespace std;
int main(int argc,char *argv[]){
int a = 10;
for (int i = 0; i < 5; i++)
{
a = a+1;
cout << &a << endl;
}
return 0;
}
a = 10
print("a += 1")
for i in range(5):
a += 1;
print(id(a))
print("a = a + 1")
for i in range(5):
a += 1;
print(id(a))
根据上面两段代码可知python每次赋值都是指针的迁移,原本地址的值不会改变,C++则是在原来的地址进行操作