Overview
In some programming languages such as C (and its close descendants like C++, Objective-C, and Java), static is a reserved word controlling both lifetime (as a static variable) and visibility (depending on linkage). The effect of the keyword varies depending on the details of the specific programming language.
Common C/C++ behavior
In C and C++, the effect of the static keyword in C depends on where the declaration occurs.
static may act as a storage class (not to be confused with classes in object-oriented programming), as can extern, auto and register (which are also reserved words). Every variable and function has one of these storage classes; if a declaration does not specify the storage class, a context-dependent default is used:
extern for all top-level declarations in a source file,
auto for variables declared in function bodies.
In these languages, the term "static variable" has two meanings which are easy to confuse:
A variable with the same lifetime as the program, as described above (language-independent); or
(C-family-specific) A variable declared with storage class static.
Variables with storage class extern, which include variables declared at top level without an explicit storage class, are static in the first meaning but not the second.
From Wikipedia (CC BY-SA 4.0).