TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 1.
What is meant by built-in scope?
Answer:
Any variable or module which is defined in the library functions of a programming language has Built-in scope or module scope.

Normally only functions or modules come along with the software, as packages. Therefore they will come under Built-in scope.

Question 2.
What is a modular programming and write the examples?
Answer:
A program can be defined into small functional modules that work together to get the outputThe process of sub dividing a computer program into separate sub programs is called modular programming.
Eg: Procedures, Subroutines and Functions.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 3.
What is a life time variable?
Answer:
The duration for which a variable is alive is called its life time of the variable.

Question 4.
What is a Module?
Answer:
A module is a part of a program. Programs are composed of one or more independently developed modules.
Modules work perfectly on individual level and can be integrated with other modules.

Question 5.
Write the types of variable scope.
Answer:
There are four types of variable scope, they are

  1. Local scope
  2. Enclosed scope
  3. Global scope
  4. Built-in-scope

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 6.
What is the use of LEGB rule?
Answer:
The LEGB rule is used to decide the order in which the the scopes are to be searched for scope resolution.
The scopes are listed bfclow in terms of hierarchy (highest to lowest).

Question 7.
What is LEGB rule?
Answer:
LEGB rule means, scope also defines the order in which variables have to be mapped to the object in order to obtain the value.

Question 8.
What is Access control?
Answer:
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.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 9.
Define
(a) Private Members
(b) Public Members
(c) Protected Members
Answer:
(a) Private Members:
Private members of a class are denied access from the outside the class. They can be handled only from within the class.

(b) Public Members:
Public members are accessible from , outside the class. The object of the same class is required to invoke a public method.

(c) Protected Members:
Protected Members of a class are accessible from within the class and are also available to its sub-classes.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 10.
What are the hierarchy of scopes using LEGB rule?
Answer:
Local (L) – Defined inside class
Enclosed (E) – Nested function concept
Global (G) – Defined at the uppermost level
Built-in (B) – Modules or Reserved names

Question 11.
Explain the variable scope with examples.
Answer:
(i) Scope refers to the visibility of variables, parameters and functions.
(ii) When you assign a variable with := to an instance (object), you are binding the variable to that instance. Multiple variables can be mapped to the same instance.
(iii) Eg: a:=5, b:=a
Here, a is first mapped to the integer 5. Here a is the variable name and 5 is the object.
(iv) Then, b is set equal to a, this actually means that b is now bound to the same integer value as a, which is 5.
(v) The scope of a variable is that part of the code where it is visible.
Eg:
Disp( ):
a:=7
(vi) When you try to display the value of a outside the procedure the program flags gives the error. So the life time of the variable is only till the end of the procedure.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 12.
Write a simple example using LEGB rule?
Answer:
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 of hierarchy (highest to lowest).
1. X : =‘outer × variable’
2. display ( ):
3. X : = ‘inner × variable’
4. display ( )
When the above statements are executed the output will be printed as
outer × variable
inner × variable

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 13.
What is a scope?
Answer:
Scope refers to the visibility of variables, parameters and functions in one part of a program to another part of the same program.

Question 14.
Why scope should be used for variable? State the reason.
Answer:

  1. The scope of a variable is that part of the code where it is visible. Scope also defines the order in which variables have to be mapped to the object in order to obtain the value.
  2. Variables are addresses (references or pointers), to an object in memory.

Question 15.
What is Mapping?
Answer:
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.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 16.
What do you mean by Namespaces?
Answer:

  • Programming languages keeps track of all these mappings with namespaces.
  • Namespaces are containers for mapping names of variables to objects.

Question 17.
How Python represents the private and protected Access specifiers?
Answer:

  1. Private members of a class are denied access from the outside class. They can be handled only from within the class.
  2. Protected members of a class are accessible from within the class and are also available to its sub-classes.

Question 18.
Define Local scope with an example.
Answer:
(i) The local scope refers to variables defined in current function.
(ii) Always a function will first look up for a variable name in its local scope.
Eg: Disp( ):
a:=10
print a
Disp( )
(iii) Here a is declared as local scope variable. And displays its value is 10.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 19.
Define Global scope with an example.
Answer:
A variable which is declared outside of all the functions in a program is called as global scope.
A global variable can be accessed inside or outside of all the functions in a program.
Eg: a:=70
Disp( )
a:=10
Print a
Disp 1( ):
Print a

Here variable a:=10 is declared inside the function, so it is known as local scope. And variable a:=70 is declared outside the function, so it is known as global scope.

Question 20.
Define Enclosed scope with an example.
Answer:
A variable which is declared inside a function which contains another function definition within it, the inner function can also access the variable of the outer function. This scope is called enclosed scope.

When a compiler or interpreter search for a variable in a programs, it first search local scope, and then search enclosing scopes.
Eg: Disp( )
a:=10
Disp 1( ):
Print a
Disp 1( ):
print a
Disp( )
Here, Disp1( ) is a member of Disp( ). So the inner function can also access the variable of the outer function.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 21.
Why access control is required?
Answer:

  1. Access control is required in object oriented programming languages.
  2. Access control is a security technique that regulates who or what can view or use resources in computing environment.
  3. In other words access control is a selective restriction of access to data.
  4. Object oriented languages control the access to class members by public, private and protected keywords.

Question 22.
Identify the scope of the variables in the following pseudo code and write its output.
Answer:
color:= Red
mycolor( ):
b:=Blue
myfavcolor( ):
g:=Green
printcolor, b, g
myfavcolor( )
printcolor, b
mycolor( )
printcolor
g – Local variable
b – Enclosed variable
color – Global variable
Output:
Red blue Green
Red blue
Red

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 23.
Explain the types of scopes for variable or LEGB rule with example.
Answer:
There are four types of variable scope.
(i) Local scope:
The local scope refers to variables defined in current function. Always a function will first look up for a variable name in its local scope.
Eg: Disp( ):
a:=10
print a
Disp( )
Here a is declared as local scope variable.
And displays its value is 10.

(ii) Global scope:
A variable which is declared outside of all the functions in a program is called as global scope.
A global variable can be accessed inside or outside of all the functions in a program.
Eg: a:=70
Disp( )
a:=10
Print a
Disp 1( ):
Print a
Here variable a:=10 is declared inside the function, so it is known as local scope. And variable a:=70 is declared outside the function, so it is known as global scope.

(iii) Enclosed scope:
A variable which is declared inside a function which contains another function definition within it, the inner function can also access the variable of the outer function. This scope is called enclosed scope.
When a compiler or interpreter search for a variable in a programs, it first Search local scope, and then search enclbsing scopes.
Eg: Disp( )
a:=10
Disp1( ):
Print a
Disp1( ):
print a
Disp( )
Here, Disp1( ) is a member of Disp( ). So the inner function can also access the variable of the outer function.

(iv)Built-in scope:
The built-in scope has all names that are pre-loaded into the program scope when we start the compiler.
Any variable or module which is defined in the library functions of a programming languages has built-in scope.
Eg: Library files, Functions, or modules come along with the software, they will ’ come under built in scope.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 24.
Write any Five Characteristics of Modules.
Answer:
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.

Question 25.
Write any five benefits in using modular programming.
Answer:
The benefits of using modular programming include:

  1. Less code to be written.
  2. A single procedure can be developed for reuse, eliminating the need to retype the code many times.
  3. Programs can be designed more easily because a small team deals with only a small part of the entire code.
  4. Modular programming allows many programmers to collaborate on the same application.
  5. The code is stored across multiple files.
  6. Code is short, simple and easy to understand.
  7. Errors can easily be identified, as they are localized to a subroutine or function.
  8. The same code can be used in many applications.
  9. The scoping of variables can easily be controlled.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Hands On Practice (Tb. P. No. 28):

Question 1.
Observe the following diagram and Write the pseudo code for the following:
Answer:

TN State Board 12th Computer Science Important Questions Chapter 3 Scoping 1

sum( ) :
num 1 := 20
sum1 ( ) :
num 1 := num 1 + 10
sum2 ( ) :
num 1 := num 1 + 10
sum2( ):
sum1 ( ):
num1 :=10
Sum( ) :
print num 1

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Choose the best answer:

Question 1.
Normally every variable defined in a program has:
(a) Global scope
(b) Local scope
(c) Enclosed scope
(d) Built-in scope
Answer:
(a) Global scope

Question 2.
Which sign is used in programming languages to map the variable and object?
(a) +
(b) –
(c) :=
(d) /
Answer:
(c) :=

Question 3.
How many type of scope variables available in python language?
(a) 2
(b) 3
(c) 4
(d) 5
Answer:
(c) 4

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 4.
Match the following:

(i) Local  (A) Nested
(ii) Enclosed  (B) Modules
(iii) Global  (C) Inside
(iv) Built in  (D) Uppermost

(a) (i) – B, (ii) – C, (iii) – A, (iv) – D
(b) (i) – C, (ii) – A, (iii) – D, (iv) – B
(c) (i) – B, (ii) – A, (iii) – D, (iv) – C
(d) (i) – C, (ii) – D, (iii) – B, (iv) – A
Answer:
(b) (i) – C, (ii) – A, (iii) – D, (iv) – B

Question 5.
Match the following:

(i) Access control (A) Outside the class
(ii) public Members (B) Within the class
(iii) Private Members (C) Security technique
(iv) Protected Members (D) Denied outside the class

(a) (i) – C, (ii) – A, (iii) – D, (iv) – B
(b) (i)- C, (ii) – B, (iii) – D, (iv) – A
(c) (i) – B, (ii) – D, (iii) – C, (iv) – A
(d) (i) – B, (ii) – C, (iii) – A, (iv) – D
Answer:
(a) (i) – C, (ii) – A, (iii) – D, (iv) – B

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 6.
Choose the incorrect pair.
(a) Module – Small Program
(b) Program – Built in scope
(c) Software – Packages
(d) Debugging – Errors
Answer:
(b) Program – Built in scope

Question 7.
Choose the correct pair.
(a) Namespaces – Mapping names
(b) LEGB – Variable rule
(c) Function – Output
(d) Scope – Language
Answer:
(a) Namespaces – Mapping names

Question 8.
Choose the incorrect statement:
(a) Modules can be separately compiled.
(b) Modules can be used by other modules.
(c) Modules are not easy to understand.
(d) Errors can easily be identified in modules.
Answer:
(c) Modules are not easy to understand.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 9.
Choose the correct statement:
(a) C++ is a function
(b) A default members in a python class are public.
(c) Python prescribes a suffixing file name of the variable.
(d) A default members in a C++ members are public.
Answer:
(b) A default members in a python class are public.

Question 10.
Assertion (A):
Local scope refers to variables defined in current function.
Reason (R):
Always, a function will first look up for a variable name in its local scope.
(a) A and R are True and R is the correct explanation for A.
(b) A is True but R is False.
(c) A is False but R is True.
(d) Both A and R are False
Answer:
(a) A and R are True and R is the correct explanation for A.

Question 11.
Assertion (A):
A module is a part of a program.
Reason (R):
Modules work not perfectly on individual level.
(a) A and R are True and R is the correct explanation for A.
(b) A is True but R is False.
(c) A is False but R is True.
(d) Both A and R are False.
Answer:
(b) A is True but R is False.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 12.
Assertion (A):
Private members of a class are accessible from the outside the class.
Reason (R):
It can be handled only from outside the class.
(a) A and R are True and R is the correct explanation for A.
(b) A is True but R is False.
(c) A is False but R is True.
(d) Both A and R are False.
Answer:
(d) Both A and R are False.

Question 13.
Assertion (A):
Protected members of a class are accessible from within the class.
Reason (R):
They can be handled only from outside the class.
(a) A and R are True and R is the correct explanation for A.
(b) A is True but R is False.
(c) A is False but R is True.
(d) Both A and R are False.
Answer:
(b) A is True but R is False.

Question 14.
Pick the odd one out:
(a) C++
(b) Java
(c) Python
(d) Module
Answer:
(d) Module

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 15.
Pick the odd one out:
(a) Procedures
(b) Scope
(c) Subroutines
(d) Functions
Answer:
(b) Scope

Question 16.
Which type of variable declared outside the functions in a program?
(a) Local
(b) Global
(c) private
(d) Enclosed
Answer:
(b) Global

Question 17.
Which of the following contain Instructions processing logic and data?
(a) Modules
(b) Scofje
(c) Variable
(d) Identifier
Answer:
(a) Modules

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 18.
Which part of a program that can see or use as variable?
(a) function
(b) scope
(c) Indentation
(d) Identifier
Answer:
(b) scope

Question 19.
Which of the following refers in the addresses to an object in memory?
(a) Functions
(b) Scope
(c) Indentation
(d) Identifier
Answer:
(c) Indentation

Question 20.
Which of the following is not a module?
(a) Indentation
(b) Procedure
(c) Subroutines
(d) Function
Answer:
(a) Indentation

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 21.
Which is called contain instructions, processing logic and data?
(a) Function
(b) Modules
(c) Scope
(d) Indentation
Answer:
(b) Modules

Question 22.
How many access control keywords are there?
(a) 2
(b) 3
(c) 4
(d) 5
Answer:
(b) 3

Question 23.
Which is a python class members?
(a) Public
(b) Private
(c) Global
(d) Protected
Answer:
(a) Public

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 24.
Which of the following is does not visibility of scope?
(a) Modules
(b) Variables
(c) Functions
(d) Identifiers
Answer:
(a) Modules

Question 25.
The duration for which a variable is alive is called:
(a) Duration Time
(b) Life Time
(c) Running Time
(d) Execution Time
Answer:
(b) Life Time

Question 26.
Which of the following refers to the visibility of variables in one part of a program to another part of the same program?
(a) Scope
(b) Memory
(c) Address
(d) Accessibility
Answer:
(a) Scope

Question 27.
The process of binding a variable name with an object is called:
(a) Scope
(b) Mapping
(c) late binding
(d) early binding
Answer:
(b) Mapping

Question 28.
Which of the following is used in programming languages to map the variable and object?
(a) ::
(b) :=
(c) =
(d) = =
Answer:
(b) :=

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 29.
Containers for mapping names of variables to objects is called
(a) Scope
(b) Mapping
(c) Binding
(d) Namespaces
Answer:
(d) Namespaces

Question 30.
Which scope refers to variables defined in current function?
(a) Local Scope
(b) Global scope
(c) Module scope
(d) Function Scope
Answer:
(a) Local Scope

Question 31.
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
Answer:
(b) Modular programming

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 32.
Which of the following security technique that regulates who can use resources in a computing environment?
(a) Password
(b) Authentication
(c) Access control
(d) Certification
Answer:
(c) Access control

Question 33.
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
Answer:
(d) Private members

Question 34.
Which members are accessible from outside the class?
(a) Public members
(b) Protected members
(c) Secured members
(d) Private members
Answer:
(a) Public members

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 3 Scoping

Question 35.
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
Answer:
(b) Protected members

TN Board 12th Computer Science Important Questions