+ 9

Is there any difference between static variable and local variable ??

23rd Sep 2017, 3:46 AM
KARRI MOUNIKA
KARRI MOUNIKA - avatar
5 Antworten
+ 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.
23rd Sep 2017, 3:59 AM
aklex
aklex - avatar
+ 3
thank u
23rd Sep 2017, 4:04 AM
KARRI MOUNIKA
KARRI MOUNIKA - avatar
+ 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.
1st Oct 2017, 10:46 AM
(BøɍƝ ťọ̄ Ćọɗë)
(BøɍƝ ťọ̄ Ćọɗë) - avatar
0
Helpful 👌🏻
23rd Sep 2017, 5:24 AM
Shivneep Brar
Shivneep Brar - avatar
0
static variables are initialised by 0 whereas local variables are initialised by garbage values
23rd Sep 2017, 3:45 PM
Abhiraj Singh Bais
Abhiraj Singh Bais - avatar