www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Static Variable Scoping in D

reply Leo Custodio <custodio.leonardo gmail.com> writes:
int x = 10;
int y = 20;

void main()
{
     import std.stdio : writeln;

     int x = 5;

     {
         int z;
         z = y / x;
         writeln("Value of z is ", z);
     }

}

// Output: Value of z is 4
Mar 23
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 24 March 2021 at 02:06:42 UTC, Leo Custodio wrote:
 [snip]
D uses the inner-most name available when it can. You can ask it to look back at top level with a prefixed .: z = y / .x; // use x from the top level
Mar 23