I am studying the Side Effect for different programming language.
For instance, in C++, if I define
x = 1;
int f(int y)
{
x = x + y;
return x;
}
and execute f(1)
the new value of x
is equal to 2.
In python, I can surely execute define the same function
x = 1
def f(y):
x = x + y
return x
but when I execute f(1)
in that situation, I obtained the error "local variable 'x' referenced before assignment."
Why do I have a different result for the same function and execution, but in different programming languages? Could I have a side effect in Python compared to C++? Is it because C++ is compiled and Python is interpreted?