Differences between scope and visibility of a variable?

1 answer

Answer

1048906

2026-07-30 14:25

+ Follow

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.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.