static Local Variables

Local variables declared static are still known only in the function in which they’re declared, but, unlike automatic variables, static local variables retain their values when the function returns to its caller. The next time the function is called, the static local variables contain the values they had when the function last completed execution. The following statement declares local variable count to be static and to be initialized to 1:

static unsigned int count = 1;

All numeric variables of static storage duration are initialized to zero by default, but it’s nevertheless a good practice to explicitly initialize all variables.

Storage-class specifiers extern and static have special meaning when they’re applied explicitly ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.