where are static, global, local variables stored in memory..... and how is volatile different from these.......
Printable View
where are static, global, local variables stored in memory..... and how is volatile different from these.......
All local variables are stored in the stack frame of the Sub/Function in which they are defined. Therefore, the address of local variables may vary with each invocation of the Sub/Function in which they are defined (because they are created each time the Sub/Function is executed, and destroyed upon exit). It is unsafe to return a pointer to a local variable, since the storage for that variable is released when the Sub/Function ends.
Conversely, GLOBAL and STATIC variables are stored in the main data memory area, so their address stays constant for the duration of the program module, so returning a pointer to a GLOBAL or STATIC variable is quite safe.
In case of volatile variable ,memory addresses are always available in chache memory hence when we need fast execution of some variable , Volatile variable is very usefull .
what is the difference between java and javascript?