+ 9
Is there any difference between static variable and local variable ??
5 Answers
+ 2
local variables are stored on the stack, while static local variables are stored in the .data/.bss section of your program. Thus the difference is that a static variable persists forever, even out of scope of it's function, while a non static local variable will not persist once it goes out of scope because of the stack.
It is also important to know that static has different meanings depending on the context. A static local variable is not the same thing as a static global variable or a static member function.
+ 3
thank u
+ 1
yeah it is major difference on it!
AĀ static local variableĀ is different from aĀ local variableĀ as aĀ static local variableĀ is initialized only once no matter how many times the function in which it resides is called and its value is retained and accessible through many calls to the function in which it is declared, e.g. to be used as a countvariable.
0
Helpful šš»
0
static variables are initialised by 0 whereas local variables are initialised by garbage values