Because it is declared as a local variable. Instead of assigning you are declaring AND assigning.
Compare two pieces of code:
int Global_variable = 10;
void some_function() {
int Global_Variable = 666;
Serial.printf("some_function() : Global_Variable is %d\r\n", Global_Variable);
}
void loop() {
Serial.printf("loop() : Global_Variable is %d\r\n", Global_Variable);
some_function();
Serial.printf("loop() : Global_Variable is %d\r\n", Global_Variable);
delay(1000);
}
And
int Global_variable = 10;
void some_function() {
Global_Variable = 666;
Serial.printf("some_function() : Global_Variable is %d\r\n", Global_Variable);
}
void loop() {
Serial.printf("loop() : Global_Variable is %d\r\n", Global_Variable);
some_function();
Serial.printf("loop() : Global_Variable is %d\r\n", Global_Variable);
delay(1000);
}
Note that in second code fragment, the Global_Variable is assigned in a right way. In first code example the same variable is declared local in the function.