+ 2
The concept is pretty straightforward Âč. for example, in case of using `static` in the context of `static Vs. dynamic variables`, a static variable's life lasts till the whole program gets terminated. void f() { int a = 10; static int b = 20; printf("a: %d, b: %d\n", ++a, ++b); } int main() { f(); f(); f(); } Output: a: 11, b: 21 a: 11, b: 22 a: 11, b: 23 The lifetime (NOT scope) of `static int b` won't end when leaving f()'s body but with the whole program. So, it keeps the previous value on the next call. _____ Âč https://en.wikipedia.org/wiki/Static_variable
31st Jan 2019, 1:15 PM
Babak
Babak - avatar