1. A static variable or method is added to the C language, indicating that this variable or method can only be accessed in the code block of this file, and external files cannot be accessed (because the linked program treats it as an internal link) static variables are stored in the field access area (similarly, static variables in the method are also stored here, rather than in the stack, so they are initialized only once during method execution ). for example:
Static int value = 20;
Static int fun ();
This definition indicates that their access permissions are only within the file block.
2. in C ++, static has a variety of different resolutions. In the file block, it represents the same meaning as the C language, and it represents different meanings in the class, static variables or static variables in the class indicate that they belong to this class, rather than class objects (this is the same as Java). Therefore, they only have one copy of memory in the memory.
3. C, C ++ const represents constants when declaring data,
A. Const data declared in C language its default link is external link (of course, extern is also external link), and cannot be used to declare the length of the array (macros must be used ).
B. the default link of the variable declared in the C ++ file is an internal link, and it can be used to declare the length of the array. Of course, it also represents different meanings in the method. for example, void fun (const char * PTR) indicates that the content pointed to by PTR cannot be changed, and the methods defined in the class such as void class: Meth () const; it means that the data in the class cannot be changed when this method is executed. Similarly, const int class: Meth () const indicates that when this method is executed, except that the data in the class cannot be changed, the Return Value of the function is still an int constant.