Students can Download Computer Science Chapter 3 Scoping Questions and Answers, Notes Pdf, Samacheer Kalvi 12th Computer Science Book Solutions Guide Pdf helps you to revise the complete Tamilnadu State Board New Syllabus and score more marks in your examinations.
Tamilnadu Samacheer Kalvi 12th Computer Science Solutions Chapter 3 Scoping
Samacheer Kalvi 12th Computer Science Scoping Text Book Back Questions and Answers
PART – 1
I. Choose The Best Answer
Question 1.
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 2.
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 3.
Which of the following is used in programming languages to map the variable and object?
(a) ::
(b) : =
(c) =
(d) = =
Answer:
(c) =
Question 4.
Containers for mapping names of variables to objects is called ………………………….
(a) Scope
(b) Mapping
(c) Binding
(d) Namespaces
Answer:
(d) Namespaces
Question 5.
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 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
Answer:
(b) Modular programming
Question 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
Answer:
(c) Access control
Question 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
Answer:
(d) Private members
Question 9.
Which members are accessible from outside the class?
(a) Public members
(b) Protected members
(c) Secured members
(d) Private members
Answer:
(a) Public members
Question 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
Answer:
(b) Protected members
PART – II
II. Answer The Following Questions
Question 1.
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 2.
Why scope should be used for variable. State the reason?
Answer:
Essentially, variables are addresses (references, or pointers), to an object in memory. When you assign a variable with := to an instance (object), you’re binding (or mapping) the variable to that instance. Multiple variables can be mapped to the same instance.
Question 3.
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.
Question 4.
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 5.
How Python represents the private and protected Access specifiers?
Answer:
Private members of a class are denied access from the outside of the class. They can be handled only within the class.
Protected members of a class are accessible from within the class and are also available to its sub-classes. No other process is permitted access to it.
PART – III
III. Answer The Following Questions
Question 1.
Define Local scope with an example?
Answer:
Local Scope:
Local scope refers to variables defined in current function. Always, a function will first look up for a variable name in its local scope. Only if it does not find it there, the outer scopes are checked.
Look at this example
On execution of the above code the variable a displays the value 7, because it is defined and available in the local scope.
Question 2.
Define Global scope with an example?
Answer:
Global Scope:
A variable which is declared outside of all the functions in a program is known as global variable. This means, global variable can be accessed inside or outside of all the functions in a program. Consider the following example
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.
Question 3.
Define Enclosed scope with an example?
Answer:
Enclosed Scope:
All programming languages permit functions to be nested. A function (method) with in another function is called nested function. 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 search for a variable in a program, it fist search Local, and then search Enclosing scopes. Consider the following example
Question 4.
Why access control is required?
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. In other words access control is a selective restriction of access to data.
In Object oriented programming languages it is implemented through access modifies.
Classical object – oriented languages, such as C++ and Java, control the access to class members by public, private and protected keywords.
Question 5.
Identify the scope of the variables in the following pseudo code and write its output?
Answer:
Output:
Red, blue, green
Red blue
Red
PART – IV
IV. Answer The Following Questions
Question 1.
Explain the types of scopes for variable or LEGB rule with example?
Answer:
LEGB rule
Scope also defines the order in which variables have to be mapped to the object in order to obtain the value. Let us take a simple example as shown below:
- x: = ‘outer x variable’
- display ( ):
- x: = ‘inner x variable’
- print x
- display ( )
When the above statements are executed the statement (4) and (5) display the result as
Output
outer x variable
inner x variable
Above statements give different outputs because the same variable name x resides in different scopes, one inside the function display( ) and the other in the upper level. The value ‘outer x variable’ is printed when x is referenced outside the function definition. Whereas when display( ) gets executed, ‘inner x variable’ is printed which is the x value inside the function definition. From the above example, we can guess that there is a rule followed, in order to decide from which scope a variable has to be picked. 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).
Types of Variable Scope:
There are 4 types of Variable Scope, let’s discuss them one by one:
Local Scope:
Local scope refers to variables defined in current function. Always, a function will first look up for a variable name in its local scope. Only if it does not find it there, the outer scopes are checked. Look at this example
On execution of the above code the variable a displays the value 7, because it is defined and available in the local scope.
Global Scope:
A variable which is declared outside of all the functions in a program is known as global variable. This means, global variable can be accessed inside or outside of all the functions in a program. Consider the following example
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.
Enclosed Scope:
All programming languages permit functions to be nested. A function (method) with in another function is called nested function. 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 search for a variable in a program, it first search Local, and then search Enclosing scopes. Consider the following example
In the above example Disp1 ( ) is defined with in Disp ( ). The variable ‘a’ defined in Disp ( ) can be even used by Disp 1 ( ) because it is also a member of Disp
Built – in Scope:
Finally, we discuss about the widest scope. The built-in scope has all the names that are pre-loaded into the program scope when we start the compiler or interpreter. Any variable or module which is defined in the library functions of a programming language has Built-in or module scope. They are loaded as soon as the library files are imported to the program.
Normally only Functions or modules come along with the software, as packages. Therefore they will come under Built in scope.
Question 2.
Write any Five Characteristics of Modules?
Answer:
Characteristics of Modules:
The following are the desirable characteristics of a module.
- Modules contain instructions, processing logic, and data.
- Modules can be separately compiled and stored in a library.
- Modules can be included in a program.
- Module segments can be used by invoking a name and some parameters.
- Module segments can be used by other modules.
Question 3.
Write any five benefits in using modular programming?
Answer:
The benefits of using modular programming include:
- 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 designed more easily because a small team deals with only 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.
Practice Programs
Question 1.
Observe the following diagram and Write the pseudo code for the following?
Answer:
sum ( ):
num 1: = 20
sum 1 ( )
num1: = num1 + 10 sum2 ( )
num1: = num1 + 10
sum2 ( ) sum1 ( ) num1: = 10
sum ( )
Print num 1
Samacheer kalvi 12th Computer Science Scoping Additional Questions and Answers
PART -1
I. Choose The Best Answer
Question 1.
Names paces are compared with ……………………….
(a) Programs
(b) Dictionaries
(c) Books
(d) Notebooks
Answer:
(b) Dictionaries
Question 2.
Write the output (value stored in b)
1. a: = 5
2. b: = a
(a) 0
(b) 3
(c) 5
(d) 2
Answer:
(c) 5
Question 3.
Find the value of a.
1. a: = 5
2. b: = a
3. a: = 3
(a) 0
(b) 3
(c) 5
(d) 2
Answer:
(b) 3
Question 4.
The ………………………. of a variable is that part of the code where it is visible.
Answer:
Scope
Question 5.
The duration for which a variable is alive is called its ……………………………
(a) Scale
(b) Life time
(c) Static
(d) Function
Answer:
(b) Life time
Question 6.
…………………………… also defines the order in which variables have to be mapped to the object in order to obtain the value.
(a) Scope
(b) Local
(c) Event
(d) Object
Answer:
(a) Scope
Question 7.
The …………………………… rule is used to decide the order in which the scopes are to be searched for scope resolution.
Answer:
LEGB
Question 8.
How many types of variable scopes are there?
(a) 1
(b) 2
(c) 3
(d) 4
Answer:
(d) 4
Question 9.
A function will first look up for a variable name in its …………………………… scope.
(a) Local
(b) Enclosed
(c) Global
(d) Built in
Answer:
(a) Local
Question 10.
A variable which is declared outside of all the functions in a program is known as …………………………… variable.
(a) L
(b) E
(c) G
(d) B
Answer:
(c) G
Question 11.
A …………………………… variable can be accessed inside or outside of all the functions in a program.
(a) Local
(b) Global
(c) Enclosed
(d) Built – in
Answer:
(b) Global
Question 12.
A function defined within another function is called …………………………… function
(a) Member
(b) Looping
(c) Nested
(d) Invariant
Answer:
(c) Nested
Question 13.
Functions are otherwise called as …………………………..
(a) Methods
(b) Attributes
(c) Class
(d) Structures
Answer:
(a) Methods
Question 14.
The scope of nested function is …………………………… scope
(a) Local
(b) Global
(c) Enclosed
(d) Built – in
Answer:
(c) Enclosed
Question 15.
When a compiler or interpreter search for a variable in a program, it first search and then search …………………………… scope
(a) L, E
(b) EG
(c) GB
(d) BL
Answer:
(a) L, E
Question 16.
Built – in scopes are called as …………………………… scope.
Answer:
Module
Question 17.
Any variable or module defined in the library functions has …………………………… scope.
Answer:
Built – in
Question 18.
Variables of built – in scopes are loaded as …………………………… files.
(a) Exe
(b) Linker
(c) Object
(d) Library
Answer:
(d) Library
Question 19.
Identify which is not a variable scope.
(a) Module
(b) Built – in
(c) Enclosed
(d) Pointer
Answer:
(d) Pointer
Question 20.
A single …………………………… can contain one or several statements closely related to each other.
Answer:
Module
Question 21.
A …………………………… is a part of a program.
(a) Code
(b) Module
(c) Flowchart
(d) System software
Answer:
(b) Module
Question 22.
Identify which is not a module?
(a) Algorithm
(b) Procedures
(c) Subroutines
(d) Functions
Answer:
(a) Algorithm
Question 23.
Find the wrong statement from the following
(a) Modules contains data and instructions
(b) Modules can be included in a program
(c) Modules cannot have processing logic
(d) Modules can be separately combined
Answer:
(c) Modules cannot have processing logic
Question 24.
Which is true about modular programming?
(a) Single procedure can be reused
(b) Single procedure cannot be reused
Answer:
(a) Single procedure can be reused
Question 25.
The arrangement of private instance variables and public methods ensures the principle of ……………………………
(a) Security
(b) Data encapsulation
(c) Inheritance
(d) Class
Answer:
(b) Data encapsulation
Question 26.
All members in a python class are by …………………………… default.
(a) Private
(b) Public
(c) Protected
(d) Local
Answer:
(b) Public
Question 27.
The members in C ++ and Java, by default are ……………………………
(a) Private
(b) Public
(c) Protected
(d) Local
Answer:
(a) Private
PART – II
II. Answer The Following Questions
Question 1.
Define life time?
Answer:
The duration for which a variable is alive is called its ‘life time’.
PART – III
III. Answer The Following Questions
Question 1.
Write the output for the pseudo code?
Answer:
- x: = ‘outer x variable’
- display( ):
- x: = ‘inner x variable’
- print x
- display Q
Output:
outer x variable
inner x variable
Question 2.
List the scope in hierarchical order from highest to lowest?
Answer:
Question 3.
Write note on modules?
Answer:
A module is a part of a program. Programs are composed of one or more independently developed modules. A single module can contain one or several statements closely related each other. Modules work perfectly on individual level and can be integrated with other modules.
Question 4.
Write note on public members?
Answer:
Public members (generally methods declared in a class) are accessible from outside the class. The object of the same class is required to invoke a public method. This arrangement of private instance variables and public methods ensures the principle of data encapsulation.