-
Static role:
1. Local variables of the modifier function:
Features: There is a default value of 0, it is only executed once, and the memory is opened up at the beginning of the operation, and the memory is placed in the whole world.
2. Modify global functions and global variables:
Features: Can only be used in this source file.
3. Modify the member variables in the class:
Features: Similar to 1, it defines multiple static y, but only one y, does not enter the size calculation of the class, and does not depend on the existence of class objects (can be called directly, and external declarations are required).
4. Member functions of the modification class:
Features: f(): There is no this pointer in parentheses, and it can only call its static function and its static variables, that is, it is modified with static and does not depend on the existence of class objects (you can call it directly without external declaration).
Main use cases of static:
1. Static method.
The static method is generally called the static method, because the static method does not depend on any object to be accessed, so for the static method, there is no this, because it is not attached to any object, since there is no object, there is no such thing. And because of this feature, you can't access the non-static member variables and non-static member methods of the class in the static method, because the non-static member method variables must depend on the specific object before they can be called.
However, it is important to note that while non-static member methods and non-static member variables cannot be accessed in static methods, static member method variables can be accessed in non-static member methods.
2. Static variables.
Static variables are also known as static variables, and the difference between static and non-static variables is that static variables are shared by all objects, have only one copy in memory, and are initialized if and only when the class is first loaded.
Non-static variables are owned by objects, are initialized when the object is created, and there are multiple copies, and the copies owned by each object do not affect each other. The initialization order of static member variables is initialized in the order defined.
3. Static** block.
Another key function of the static keyword is to form static blocks to optimize program performance. A static block can be placed anywhere in a class, and there can be multiple static blocks in a class.
When the class is first loaded, each static block is executed in the order in which it was static, and only once. The reason why static blocks can be used to optimize program performance is because of its peculiarity: it is only executed once when the class is loaded.
-
A member function of a decorating class
Features: f(): There is no this pointer in parentheses, and it can only call its static function and its static variables, that is, it is modified with static and does not depend on the existence of class objects (you can call it directly without external declaration).
2. Modify global functions and global variables:
Features: Can only be used in this source file.
3. Modify the member variables in the class:
Features: Similar to 1, it defines multiple static y, but only one y, does not enter the size calculation of the class, and does not depend on the existence of class objects (can be called directly, and external declarations are required).
Related information
Static global variables have the following characteristics:
This variable allocates memory in the global data zone; Uninitialized static global variables are automatically initialized to 0 by the program (the value of an automatic variable declared in the body of a function is random unless it is explicitly initialized, while an automatic variable declared outside the body of a function is also initialized to 0).
A static global variable is visible when it declares its entire file, but not outside the file; Static variables all allocate memory in the global data area, including the static local variables that will be mentioned later. The general program stores the newly generated dynamic data in the stack, and the automatic variables inside the function are stored in the stack.
-
1) The scope of the static variable in the function body is the function body, which is different from the auto variable, the memory of the variable is only allocated once, so its value will remain the last value when it is called next time;
2) The static global variables in the module can be accessed by the functions used in the module, but cannot be accessed by other functions outside the module;
3) The static function in the module can only be called by other functions in the module, and the scope of use of this function is limited to the module that declares it;
4) The static member variables in the class belong to the whole class, and there is only one copy of all objects in the class;
5) The static member function in the class belongs to the whole class, and this function does not receive this pointer, so it can only access the static member variables of the class.
-
The static keyword does the following:
1. Modify variables
Static global variable: A global variable is preceded by a static modifier, and the variable becomes a static global variable. We know that all variables can be accessed throughout the project, and after adding the static keyword, this variable can only be accessed within this file.
So, here, the role of static is to limit the scope.
Static Local Variable: When a static variable is added to the static modifier, the variable becomes a static local variable. We know that local variables are destroyed when they leave the defined function, and when Static is used to modify it, its scope remains until the end of the program.
Therefore, the role of static here is to define the life cycle.
2. Modifier function
If the modifier function becomes a static function, the scope of the function is limited to this file, and cannot be called by other letter wheel files.
Introduction to the c-language
C language is a process-oriented, abstract general-purpose programming language, which is widely used in low-level development. C can compile and process low-level memory in a simple way. C is a language that produces only a small number of machine languages and can run efficient programs without any runtime support.
-
Static role:
1. Local variables of the modifier function: Features: There is a default value of 0, which is only executed once, and the memory is opened up at the beginning of the operation, and the memory is placed in the world.
2. Modify global functions and global variables:
Features: It can only be used in the original cavity wheel file.
3. Modify the member variables in the class: Features: Similar to 1, define multiple static y, but only one y, do not enter the size calculation of the class, and do not depend on the existence of the storage simplicity of the class object (can be called directly, external declaration is required).
Variables that are declared static are calledStatic variablesor class variables.
You can refer to static variables directly by class name, or you can refer to static variables by instance name, but it's best to use the former, as the latter tends to confuse static variables with generic variables. Static variables are associated with a class, and all instances of the class share a static variable.
Methods that are declared static are called static methods or class methods. Static methods can directly call static methods to access static variables, but cannot directly access instance variables and instance methods. You can't use the this keyword in a static method because it doesn't belong to any instance.
The above content reference: Encyclopedia-static
-
1. Modifier function.
The static modifier makes it possible for a function to only be called in the file that contains the function's definition. For static functions, the declaration and the definition need to be in the same folder.
Middle. 2. Modify member variables.
Decorate the data members of a class with static to make them global variables of the class.
It is quietly shared by all objects of the class, including the objects of the derived class, all of which maintain only the same instance. Therefore, the static member must be initialized outside the class, not in the constructor.
, but it is also possible to modify static data members with const to initialize within the class.
3. Modify member functions.
Decorate the member function with static, so that the class only has this function, and all objects share the function, without this pointer, so that only the static member variables of the class can be accessed. Static members are independently accessible without creating any object instances.
4. Modify local variables.
When a static modifier is used to modify a local variable, the modified variable becomes static.
It is stored in a static area. The lifecycle of the data stored in the static area is the same as that of the program, in the main function.
Initialized before, destroyed when the program exits.
5. Modify global variables.
Global variables are inherently stored in a static area, so static does not change where they are stored. However, static restricts its link attributes. A global variable that is static can only be accessed by the file that contains the definition.
-
Official service. Official**.
How would you rate this? Collapse.
-
Static role:
1. Local variables of the modifier function:
Features: There is a default value of 0, it is only executed once, the memory is opened up at the beginning of the operation, the memory is placed in the global 2, and the global functions and global variables are modified:
Features: Can only be used in this source file.
3. Modify the member variables in the class:
Features: Similar to 1, it defines multiple static y, but only one y, does not enter the size calculation of the class, and does not depend on the existence of class objects (can be called directly, and external declarations are required).
4. Member functions of the modification class:
Features: f(): There is no this pointer in parentheses, and it can only call its static function and its static variables, that is, it is modified with static and does not depend on the existence of class objects (you can call it directly without external declaration).
-
The static keyword has at least one of the following n functions:
1) Set the storage domain of the variable, the scope of the static variable in the function body is the function body, different from the auto variable, the memory of the variable is only allocated once, so its value will still maintain the last value in the next call;
2) Limit the scope of variables, static global variables in the module can be accessed by the functions used in the module, but cannot be accessed by other functions outside the module;
3) Limit the scope of the function, the static function in the module can only be called by other functions in the module, and the scope of use of this function is limited to the module that declares it;
4) The static member variable in the class means that it is shared by all instances of the class, that is, when an instance of a class modifies the static member variable, its modified value is seen by all other instances of the class;
5) The static member function in the class belongs to the whole class, and this function does not receive this pointer, so it can only access the static member variables of the class.
-
A variable declared static is essentially a global variable. Methods that are declared static have the following limitations:
They can only call other static methods.
They only have access to static data.
They can't refer to this or super in any way and if you need to initialize your static variable by computation, you can declare a static block, and the static block is only executed once when the class is loaded.
-
C++ procedural static is the same as C's. There are two uses of Static in C++: Static in Process-Oriented Programming and Static in Object-Oriented Programming.
The former applies to ordinary variables and functions, and does not involve classes; The latter mainly illustrates the role of static in classes.
1. Static in process design
1. Static global variables.
The global variable is preceded by the keyword static, and the variable is defined as a static global variable. Let's start with an example of a static global variable, as follows:
example 1
#include
void fn();
static int n;Define the static global variable void main().
void fn()
void fn() defines a static function.
Benefits of Defining Static Functions:
Static functions cannot be used by other files;
Functions with the same name can be defined in other files without conflict;
-
Statically allocated variables. The variable has been allocated memory and initialized during the compilation phase, unlike the dynamically allocated local variables in the function, they only allocate memory when the function is called, and the memory is released after the call, while the static variable is statically allocated and still exists after the function is called, no matter how many calls in the program, the same memory address is used.
You can query some of the segmented comments in PLSQL to see if the problem is in **ah, and you can't see the problem roughly. >>>More
There are two types of keyword search results, one is in the ad that spent money to do PPC (there are two words promotion after the green display **) or the right side of the page is all ad positions; The other is that the number of page views is very high (such as some industry **, such as lawyer network, law 168, etc.) will be automatically included, these links will be ranked behind the advertisements that have spent money to promote, and it is difficult for the general company to be included naturally, but some network companies can do it through optimization, in fact, optimization is to deceive the number of views through technology! By extension, Google is the same, but it's the ads that say the sponsored link.
Oracle's parser processes the table names in the From clause in right-to-left order, the table written at the end of the From clause (the driving table) will be processed first, and if the FROM clause contains multiple tables, you must select the table with the fewest records as the base table. If you have more than 3 table join queries, you need to select an intersection table as the underlying table, which is the table that is referenced by other tables. >>>More
I won't copy it, SEO keywords can start with a simple one, such as: long-tail keywords, words with low index, but to ensure that the words you make are valuable, someone searches for valuable words, otherwise it is a waste of time to do it. Why do you say start with the simple, because simple words are easy to get on the homepage and reduce the cycle. >>>More
Keyword optimization tips.
1. Location layout. >>>More