Home >Backend Development >C#.Net Tutorial >What is the function of static keyword in c language
What is the function of the static keyword in C language
In C, static mainly defines global static variables, defines local static variables, and defines static function.
Recommended learning: c language video tutorial
In daily use, static usually has two functions:
1. Modification Variable
■ Static global variable: Add the static modification before the global variable, and the variable becomes a static global variable. We know that all variables can be accessed in the entire project (defined in one file, and added with the extern keyword declaration when used in other files). After adding the static keyword, this variable can only be accessed within this file. . Therefore, here, the role of static is to limit the scope.
■ Static local variables: After the static modification is added to the local invariant, the variable becomes a static local variable. We know that local variables will be destroyed after leaving the defined function, and when modified with static, its scope will last until the end of the entire program. Therefore, the role of static here is to limit the life cycle.
2. Modified function
■ If you modify the function, the function becomes static function. The scope of the function is limited to this file, and Cannot be called by other files.
For more c languageprogramming tutorial, please pay attention to the PHP Chinese website!
The above is the detailed content of What is the function of static keyword in c language. For more information, please follow other related articles on the PHP Chinese website!