What is the purpose of the keyword “static” in the C language?
In the C language, the static keyword serves several purposes:
- Static variables are variables within a function that are defined with the keyword “static.” They have a lifespan that lasts for the entire duration of the program, rather than just when the function is called. The scope of static variables is still within the function where they are declared, but their value persists even after the function call ends. The next time the function is called, the static variable will retain the value it had at the end of the previous call.
 - Static function: By using the static keyword in a function declaration, it indicates that the function is only visible in the source file where it is defined and cannot be called by other files. The main purpose of a static function is to restrict the function’s scope and prevent naming conflicts with functions in other source files.
 - Static global variable: A variable that is declared outside of a function with the static keyword is called a static global variable. Its scope is limited to the source file where it is defined. Static global variables exist throughout the entire runtime of a program, but can only be accessed within the source file where they are defined and cannot be accessed by other source files.
 - Static member variable: In object-oriented programming, the static keyword can also be used for class member variables, indicating that the member variable is a shared variable for the class, with all objects of the class sharing the same memory space for the static member variable.
 
In summary, the role of static can be summed up as: limiting scope, extending lifespan, and sharing memory space.