10.2.2 Static Variables

All static variables have permanent storage duration, even those defined inside a function which are “local static” variables. Local static variables only have scope in the function or block in which they are defined, but unlike auto variables, their memory is reserved for the entire duration of the program. Thus, they are allocated memory like other non-auto variables. Static variables may be accessed by other functions via pointers, since they have permanent duration.

Variables which are static are guaranteed to retain their value between calls to a function, unless explicitly modified via a pointer.

Variables which are static and initialized have their initial value assigned only once during the program's execution. Thus, they may be preferable over initialized auto objects which are assigned a value every time the block they are defined in begins execution. Any initialized static variables are initialized in the same way as other non-auto initialized objects by the runtime start-up code, see 5.4.3 Peripheral Library Functions. Static variables are located in the same sections as their non-static counterparts.