A query about lexical scoping
I try to understand lexical-scoping. In lexical-scoping, I have this code, C like syntax:
main{
f1(){
int y = 8;
}
int y = 1; //*
f1();
}
After the execution of f1()
line, will the value of y
variable in main (I put * next of 开发者_StackOverflow中文版it) remain 1 or change to 8?
It will remain 1. You have two completely distinct variables. Changes to one do not affect the other.
精彩评论