XII CS Chapter 3 - Scoping Notes 2025-2026
XII CS Chapter 3 - Scoping Notes 2025-2026
Standard XII
Computer Science notes
1.Choose the correct answers :
1. Which of the following refers to the visibility of variablesin one part of a program to
another part of the same program.
(A) Scope
(B) Memory (C) Address
(D) Accessibility
2. The process of binding a variable name with an object is called
(A) Scope
(B) Mapping (C) late binding
(D) early binding
3. Which of the following is used in programming languages to map the variable and object?
(A) ::
(B) :=
(C) =
(D) ==
4. Containers for mapping names of variables to objects is called
(A) Scope
(B) Mapping (C) Binding
(D) Namespaces
5. Which scope refers to variables defined in current function?
(A) Local Scope
(B) Global scope
(C) Module scope
(D) Function Scope
6. The process of subdividing a computer program into separate sub-programs is called
(A) Procedural Programming
(B) Modular programming
(C)Event Driven Programming
(D) Object oriented Programming
7. Which of the following security technique that regulates who canuse resources in a
computing environment?
(A) Password
(B)Authentication
(C) Access control
(D) Certification
8. Which of the following members of a class can be handled only from within the class?
(A) Public members
(B)Protected members
(C) Secured members
(D) Private members
9. Which members are accessible from outside the class?
(A) Public members
(B)Protected members
(C) Secured members
(D) Private members
10. The members that are accessible from within the class and are also available to its
subclasses is called
(A) Public members
(B)Protected members
(C) Secured members
(D) Private members
Part 2
Two marks
1. What is a scope?
Scope refers to the accessibity of a variable with in one part of a program to another part of the
same program.
2.Why scope should be used for variable. State the reason.
i.scope should be used for variable because it limits variable’s scope to a single definition.
ii.The scope of a variable is that part of the code where it is visible.
a:=10 o/p : 7
Disp(): 10
a:=7
print a
Disp()
print a
3. What is Mapping?
The process of binding a variable name with an object is called mapping.
= (equal to sign) is used in programming languages to map the variable and object.
4. What do you mean by Namespaces?
Namespaces are containers for mapping
names of variables to objects.
(name := object) in programming language.
This allows access to objects by names you
choose to assign to them.
Eg: a:=5 a is mapped to the value 5.
5. How Python represents the private and protected Access specifiers?
Python prescribes a convention of adding a prefix_ _(double underscore) results in a variable
name or method becoming private.
· Example: self._ _n2=n2
·Adding a prefix_(single underscore) to a variable name or method makes it protected.
● Example: self._sal =sa
Part 3
Answer the following questions
1.Define Local scope with an example.
· Local scope refers to variables defined in current function.
·A function will always look up for a variable name in its local scope.
·Only if it does not find it there,the outer scopes are checked.
● Example:
Disp():
a:=7
print a
Disp()
Output
7
·On execution of the above code the variable a displays the value 7,because it is defined and
available in the local scope.
2.Define Global scope with an example.
· A variable which is declared outside of all the functionsin a program is known as global
variable.
● Global variable can be accessed inside or outside of all the functions in a program.
● Example:
a:=10
Disp():
a:=2
print a
Disp()
print a
Output:
2
10
Disp():
a:=10
Disp l():
a:=10
print a
Disp l()
print a
Disp()
Output:
10
10
4.Why access control is required?
·Access control is a security technique that regulates who or what can view or use resources in
a computing environment.
· It is a fundamental concept in security that minimizes risk to the object.
· In other words access control is a selective restriction of access to data.
·In OOPS Access control is implemented through access modifiers.
5.Identify the scope of the variables in the following pseudo code and write its output.
color:=Red
mycolor();
b:=Blue
myfavcolor():
g:=Green
print color,b,g
myfavcolor()
print color,b
mycolor()
print color
OUTPUT:
Red Blue Green
Red Blue
Red
Scope of Variables :
Variables Scope
Color:=Red Global
b:=Blue Enclosed
G·=Green Local
Part 4
1.Explain the types of scopes for variable or LEGB rule with example.
SCOPE :;
·Scope refers to the visibility ofvariables,parameters and functions in one part of a program to
another part
of the same program
TYPES OF VARIABLE SCOPE;
>Local Scope
Enclosed Scope
Global Scope
Built-in Scope
LEGB RULE:
· The LEGB rule is used to decide the order in which the scopes are to be searched for scope
resolution.
»The scopes are listed below in terms ofhierarchy (highest to lowest).
Local(L) :Deined inside function/elass
Enclosed(E) :Deined inshde endlosing functons (Nested functon concept)
Global(G) :Deined arтhе иррегтояг 1еусГ
Built-in(B) :Reserved names in built-in functions(modules)
i)LOCAL SCOPE:
·Local scope refers to variables defined in current function.
·A function will always look up for a variable name in its local scope
.Only if it does not find it there,the outer scopes are checked.
· Example:
Disp( ):
а:=7
print a
Disp( )
Оиtриt
7
·On execution of the above code the variable a displays the value 7,because it is defined and
available in
the local scope
ii)ENCLOSED SCOPE;
·A variable which is declared inside a function which contains another function definition with in
it,the inner function can also access the variable of the outer function.This scope is called
enclosed scope.
● When a compiler or interpreter searches for a variable in a program,it first search Local,and
then search Enclosing scopes:
Example
Disp():
a:=10
Disp l():
a:=10
print a
Disp l()
print a
Disp()
Output:
10
10
In the above example Disp10 is defined within Disp0.The variable a'defined in DispO can be
even
used by Disp1()because it is also a member of Disp().
iii)GLOBAL SCOPE;
· A variable which is declared outside of all the functions in a program is known as global
variable.
· Global variable can be accessed inside or outside of all the functions in a program.
● Example:
a:=10
Disp():
a:=7
print a
Disp()
print a
7
10
·On execution of the above code the variable a which is defined inside the function displays the
value 7 for the function call Disp()and then it displays 10,because a is defined in global scope.
iv)BUILT-IN-SCOPE;
·The built-in scope has all the names that are pre-loaded into the program scope when we start
thecompiler or interpreter.
·Any variable or module which is defined in the library functions of a programming language has
Built-in or module scop.
● Example:
a:=10
Disp():
a:=7
print a
Disp()
print a
7
10
2.Write any Five Characteristics of Modules.
The following are the desirable characteristics of a module.
1.Modules contain instructions,processing logic,and data.
2.Modules can be separately compiled and stored in a library.
3.Modules can be included in a program.
4.Module segments can be used by invoking a name and some parameters.
5.Module segments can be used by other modules.
3.Write any five benefits in using modular programming.
·Less code to be written.
·A single procedure can be developed for reuse,eliminating the need to retype the code many
times.
● Programs can be desiened easilv because a small team deals with onlv a small part of the
entire code.Modular programming allows many programmers to collaborate on the same
application.
·The code is stored across multiple files.
·Code is short,simple and easy to understand.
·Errors can easily be identified,as they are localized to a subroutine or function.
·The same code can be used in many applications.
·The scoping of variables can easily be controlled.
Additional Questions
1.What is life time?
The duration for which a variable is alive is called its ‘life time’of the variable.
2.What Will be the output of the following algorithm.
1. x:= 'outer x variable'
2. display():
3.x:= 'inner x variable'
4.print x
5. print x
6. display()
Output
outer x variable
inner x variable