Contents Introduction Names Variables The Concept of Binding Type Checking Strong Typing Type Equivalence Scope Scope and Lifetime Referencing Environments Named Constants Introduction



Download 396.24 Kb.
Page14/16
Date18.02.2022
Size396.24 Kb.
#58269
1   ...   8   9   10   11   12   13   14   15   16
13516098

while (...) {

int index;

...

}

Ada: declare Temp : Float;

begin

...

end

Evaluation of Static Scoping

  • In most programming languages including C, C++, and Java, variables are always statically (or lexically) scoped i.e., binding of a variable can be determined by program text and is independent of the run-time function call stack.
  • C++ and Ada allow access to these "hidden" variables
    • In Ada: unit.name
    • In C++: class_name::name

Evaluation of Static Scoping


#include

int x = 10;

// Called by g()

int f()


{

return x;

}

// g() has its own variable



// named as x and calls f()

int g()


{

int x = 20;

return f();

}

int main()



{

printf("%d", g());

printf("\n");

return 0;

}

The output for the given program is 10, i.e., the value returned by f() is not dependent on who is calling it (Like g() calls it and has a x with value 20). f() always returns the value of global variable x.



Download 396.24 Kb.

Share with your friends:
1   ...   8   9   10   11   12   13   14   15   16




The database is protected by copyright ©ininet.org 2024
send message

    Main page