Great question on static guys, It helped me, hope it helps you too. https://gateoverflow.in/2176/gate-cse-201…

ravikaranrathore

Great question on static guys,
It helped me, hope it helps you too.

https://gateoverflow.in/2176/gate-cse-2012-question-48
int a, b, c = 0; void prtFun(void); main() { static int a = 1; /* Line 1 / prtFun(); a += 1; prtFun(); printf(“ \n %d %d ”, a, b); } void prtFun(void) { static int a = 2; / Line 2 */ int b = 1; a += ++b; printf(“ \n %d %d ”, a, b); }

Points to remember for static:

Scope: Within the Body where declared

Lifetime : Whole Program

Default value: 0

Initialization: Possible only once within the body 

Memory Segment: Data Segment (Hence values of the variables can be altered at run time)