0

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 it) remain 1 or change to 8?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
stedkka
  • 345
  • 2
  • 4
  • 14

1 Answers1

1

It will remain 1. You have two completely distinct variables. Changes to one do not affect the other.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467