开发者

A query about lexical scoping

开发者 https://www.devze.com 2023-03-09 08:05 出处:网络
I try to understand lexical-scoping. In lexical-scoping, I have this code, C like syntax: main{ f1(){ int y = 8;

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

精彩评论

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

关注公众号