answersLogoWhite

0


Best Answer

Scope of a variable is the lines of code from which it can be seen and/or manipulated. Scope can be thought of as visibility, because a variable's scope is where it is visible from.

A variable declared within a function (or any block, for that matter) has scope only within that block. It is visible within that block, and from within any contained block, but not from within any containing (outer) blocks. However, it should be noted that if a variable's name is reused in a nested declaration, then the outer variable loses scope within that block. As a result, you can reuse, for instance, the variable "i" within a new block without compromising any use outside that block.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

the scope of a variable is where it exists, the different scopes can be public, private, protected etc, public can be seen from anywhere, private only within the class, (not fully sure about protected) or you can have a variable within a { } and that nesting level is the only place it exists.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Scope of a variable is the set of lines of code from where you can refer to it. Lifetime, on the other hand, is the time from creation to the time of deletion.

As an example, a variable declared outside of any function, i.e. at global level, is considered to have full scope and static lifetime for the duration of the program's execution. The only exception would be within another block or function, where you might redefine the variable - in that case, you lose scope, but the original variable is not affected.

As an example of lifetime, a variable declared with automatic attributes, inside a block, exists from the point where you create it to the point where you leave the block. At that point, the variable ceases to exist, because the stack space used for it has been reclaimed.

This answer is:
User Avatar

User Avatar

Wiki User

16y ago

discuss the relative strengths of low-fi compared with hi-fi prototyping

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Scope determines the life time of a variable.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Scope refers to where variable can be used in your program

where as

Visibility refers to lifetime of variable.

Though sense are different but meaning is same.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Differences between scope and visibility of a variable?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Explain the scope and visibility of variables in c plus plus function?

If you define a variable inside of your function, the variable can be referred and used only inside of that function. It means that you will not able to use the variable in another function (including main). Area of code where your variable can be used after declaration is usually called visibility of the variable.


Describe the differences between local and module-level variables?

local Variable A Local variable is a variable whose scope is limited to the Block of the Subroutine defining it. Private Sub Command1_Click Dim a as integer End Sub Module Level Variable A Module Level variable is a variable whose scope is limited to the Form Module defining it. Public Sub Command1_Click Dim a as integer End Sub Global Level Variable A Global Level variable is a variable whose scope can be limited to the entire project defining it. Private Sub Classjnitialize () Dim a As Integer End Sub


What is the scope of any variable?

The Scope of a variable defines the areas of a program where this variable would be visible and can be used. For ex: a. Method variables - are visible only inside the method where they are declared and hence their scope is only the method b. Class variables - are visible inside the class and can be used by any method inside the class and hence their scope is the whole class.


What is mean by scope in c language?

Scope is generally defined as variable or functions life... Generally the life is between the opening braces and close braces "{ }" ... If thee variable is defined as "static" and if is defined outside a function then its scope is in same file. if defined as global then its scope is across the files.


What is out of scope in returning objects in java?

if u declare variable in method & tray to use this variable outside the method then it is out of scope

Related questions

Explain the scope and visibility of variables in c plus plus function?

If you define a variable inside of your function, the variable can be referred and used only inside of that function. It means that you will not able to use the variable in another function (including main). Area of code where your variable can be used after declaration is usually called visibility of the variable.


Describe the differences between local and module-level variables?

local Variable A Local variable is a variable whose scope is limited to the Block of the Subroutine defining it. Private Sub Command1_Click Dim a as integer End Sub Module Level Variable A Module Level variable is a variable whose scope is limited to the Form Module defining it. Public Sub Command1_Click Dim a as integer End Sub Global Level Variable A Global Level variable is a variable whose scope can be limited to the entire project defining it. Private Sub Classjnitialize () Dim a As Integer End Sub


What is the scope of any variable?

The Scope of a variable defines the areas of a program where this variable would be visible and can be used. For ex: a. Method variables - are visible only inside the method where they are declared and hence their scope is only the method b. Class variables - are visible inside the class and can be used by any method inside the class and hence their scope is the whole class.


What is mean by scope in c language?

Scope is generally defined as variable or functions life... Generally the life is between the opening braces and close braces "{ }" ... If thee variable is defined as "static" and if is defined outside a function then its scope is in same file. if defined as global then its scope is across the files.


Scope of static variables?

Scope of static variable is with in the file if it is static global. Scope of static variable is with in the function if variable is declared local to a function. But the life time is throughout the program


What is the scope of a data statement?

A global scope is an entire computer program. A variable scope is the part of the program in which the variable may be accessed. (close enough)


Which specifier indicates that a variable's reserved space in the memory can be erased or relocated when the variable is out of its scope?

There is no such thing. When the program leaves the scope of the variable, it will be release the memory of the variable automatically and unconditonally.


What is out of scope in returning objects in java?

if u declare variable in method & tray to use this variable outside the method then it is out of scope


Is possible to declare a variable in a method and declare it a main?

The same identifier (variable name) may be used for at most one variable in each scope. Each method has its own scope, in addition to the global scope which is accessible from all others. However, each scope would have a different variable than every other scope despite using the same name for it.


In most languages where does a local variables scope begin and end?

A local variable only exists within the scope in which it is declared. As soon as the scope ends, the variable ceases to exist. { // beginning of a scope, i does not yet exist int i = 42; // local variable declared, i now exists } // end of scope, i no longer exists


What brand of scope is on the Remington 770?

A Bushnell 3-9x40 variable scope


What is the difference between variable declared inside the declaration part and variable declared in scriptlet part?

Variable declared inside declaration part is treated as a global variable, which means after translation of jsp file into servletthat variable will be declared outside the service method as an instance variablethe scope is available to the complete jspVariable declared inside a scriplet will be declared inside a service method as a local variable and the scope is with in the service method.