C++
#include <iostream>
using namespace std;
void doSomething(int y)
{
cout << y << " "<< & y << endl;
}
int main()
{
int x(0);
cout << x << " " << & x << endl;
doSomething(x);
return 0;
}
Python
def doSomething(y):
print(y, id(y))
x = 0
print(x, id(x))
doSomething(x)
I think their code should return same result however C ++ result is
0 00000016C3F5FB14
0 00000016C3F5FAF0
Python result is
0 1676853313744
0 1676853313744
i don't understand why variable's address isn't changed in Python while variable's address is changed in C++