I read this in Kathy Sierra's book:
"Local variables are sometimes called stack, temporary, automatic, or method variables, but the rules for these variables are the same regardless of what you call them."
Why are the local variables called automatic?
In computer programming, an automatic variable is a local variable which is allocated and deallocated automatically when program flow enters and leaves the variable's scope. The scope is the lexical context, particularly the function or block in which a variable is defined.
The Java standard demands that every local variable must be explicitly initialized before being used. This differs from instance variables, which are implicitly initialized with default values (which are 0 for numbers and null for objects).
auto variables (not to be confused with auto keyword) are typically non-static local variables. They are stored in what is usually called "stack" space. "Local variables are non existent in the memory after the function termination", You probably mean Scope, { , } and not function termination.
Local variables are declared in methods, constructors, or blocks. Local variables are created when the method, constructor or block is entered and the variable will be destroyed once it exits the method, constructor, or block. Access modifiers cannot be used for local variables.
Local variables automatically cease to exist when the execution of the block in which they are declared completes.
{
int a = some_initialisation_value;
....
}
// a automatically vanishes here.
Good ol' Wikipedia
In computer programming, an automatic variable is a lexically-scoped variable which is allocated and de-allocated automatically when program flow enters and leaves the variable's scope. The term local variable is usually synonymous with automatic variable, since these are the same thing in many programming languages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With