12th standard computer science public exam 2022 important questions
12th computer science important questions 2022 for public exam |
Chapter 3 SCOPING
Chapter 1 Function Important Questions 2022
12th standard computer science important 5 mark questions
1.Explain the types of scopes for variable or LEGB rule with example.
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:
1. x:= ‘outer x variable’
2. display():
3. x:= ‘inner x variable’
4. print x
5. 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 xvariableโ 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).
Write any five benefits in using modular programming.
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.
Leave a Reply