Name Visibility :
Named
entities, such as variables, functions, and compound types need to be
declared before being used in programs. The point in the program
where this declaration happens influences its visibility.
An entity declared outside any block has global scope called “Global variables” , meaning that its name is valid anywhere in the code. While an entity declared within a block, in a function or as a function parameters has block scope, and is only visible within the specific block in which it is declared, but not outside it. Variables with block scope are known as “Local variables”.
An entity declared outside any block has global scope called “Global variables” , meaning that its name is valid anywhere in the code. While an entity declared within a block, in a function or as a function parameters has block scope, and is only visible within the specific block in which it is declared, but not outside it. Variables with block scope are known as “Local variables”.
For
example :
- we can also call a variable as Local variable ,If we can also declare it in the block or constructor.
Here b can be accessed inside the block also but c can’t be accessed in function d.
- If the global variable value is changed anywhere in the program (i.e. with out declaring it ) ,it's value will be changed.
Without
compiling it directly in the compiler,once u check the output by u r
self. Then u will get the clear idea how the values of variables will
change.
- Suppose if u want two
values for the same variable in the same function, then a new
concept namespace
is to be used.
Here is a set of programs for u for practice.
1.
2.
3.
4.
5.
The answers for this programs are available in the below link :
CLICK HERE