STATIC:It will be executed only once in it’s lifetime.
Solution:
Let’s give the numbering for the better understanding-
int a, b, c = 0;
void prtFun(void);
main()
{
1-→ static int a = 1; /* Line 1 */
2-→prtFun();
3-→a += 1;
4-→prtFun();
5-→printf(“ \n %d %d ”, a, b);
}
void prtFun(void)
{
6-→static int a = 2; /* Line 2 */
7-→int b = 1;
8-→a += ++b;
9-→printf(“ \n %d %d ”, a, b);
1-->a=1(Now this will never be executed coz of static variable)
2—→ 6→ a=2(Same reason this will never be executed again due to static variable)
7→ b=1
8→ a+ ++b=2+2=4
So a=4,b=2
9→ O/P a=4,b=2
back to main
3 –→ a=a+1=1+1=2;
4--→ 6→now a=4 it won’t be changed to 2 because of the static variable.
7→ b=1 Since b will bw reset to 1 again as it is not static
8→ a=a+ ++b=4+2=6
9→ a=6,b=2 o/p
back to main
5-→ a=2,b=0 o/p
o/p 4 2
6 2
2 0