Static variable Flashcards
On infinite function calls , what happens?
Stack size is over / Stack overflow error(runtime error mostly due to logical mistakes)
if(10.5)
True
if(-11)
true
if(‘A’)
true
if(0.0)
False
if(null)
False
if(0)
False
if(‘\o’)
False
a=5
POSTFIX: x=a–
OR
PREFIX: x=–a
POSTFIX: x=5
PREFIX: x=4
What happens if we use static keyword for a local variable for instance,
static int a=5;
It is local but will be stored in static area and compiler will assign it memory during compile time. No matter how many times the function is called static memory is only allocated once.
Even in multiple calls of the same function in which a static variable is declared, how many times is that variable allocated memory?
Only once in static area, all function calls share the same value of the variable as stored in static area.
If a same fn. is called again and again and it includes declaration of a variable which is not static, what happens?
Memory is allocated to that variable again and again and it is initialized again & again
Stack overflow occurs when functions are called infinitely but not for an infinite loop, WHY?
Because when function is called , activation records are pushed into stack but infinite loop doesn’t affect stack.
Default value of static variable?
0
Global variable are stored in?
Static area