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 to external identifiers such as global variables and global function names. In Appendix F, C Legacy Code Topics, we discuss using extern and static with external identifiers and multiple-source-file programs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.181.209