开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜