12th computer science important questions 2022 for public exam

 12th standard computer science public exam 2022 important questions


12th computer science important questions 2022 for public exam
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.






Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Search


Categories