In above example we have declare a function name fun1(). In that function we have initialized a static variable i with value 0.
On next line we are incrementing value of i by 1. By now value of i is 1.
On next line we are printing the value of i which is 1.
Now we call this function in main() function for two times, that means block of code written in fun1() function will get executed two times.
First when function is called compiler jumps to function fun1() and start executing it. First it will initialize static variable i with value 0.
After that value of i will get incremented to 1, and after it will print value of i which is 1.
And when execution of the function fun1() is complete i will not get destroyed but it will remain in memory.
When second time the function is called then compiler will not initialized i with value 0 because i was not destroyed i was saved in memory because we declared i as a static variable. Static keyword allows us to save variable in memory while the program is running.
So when second when fun1() is called it will skip initialization part and increment the value of i by 1 after increment the value of i becomes 2 and that is why it will print value of i is 2 in second call.