Monday, 21 April 2014


SCOPE: A scope in any programming language is the region of that program where this defined variables can have their own existence and beyond this scope of a particular variable, that variable can't be accessed.
What is  Local Variable?
Variable whose existence is known only to the main program or functions are called local variables. Local variables are declared within the main program or a function.
auto data_type identifier

What is The Scope of Local Variables?
Local variables have a scope inside the function it is declared and not outside it.

What is Lifetime?
The time period for which a variable exists in the memory is known as lifetime of variable.

What is Lifetime of Local Variable?
Lifetime of a local variables starts the moment when programmer enters the function inside  which the variable is declared and gets destroyed when programmer exists from the function.

What is Global Variable?
Variables whose existence is known to the both main() as well as other functions are called global variables. Global variables are declared outside the main() and other functions.
What is The Scope of Global Variable?
Global variables as the name says can be accessed from any part of a program and can be used in multiple functions. for this, the variables are defined before the "main" function

What is The Lifetime of Global Variable?
Global variables are bound to exist in the memory for as long as the program is in running state. These variables get are destroyed as soon as the program terminates. These variables occupy memory for a longer duration in comparison with than local variables.

No comments:

Post a Comment