const static
时间: 2023-08-09 20:04:57 浏览: 72
"const" and "static" are two different keywords in C++.
"const" is used to declare a constant value that cannot be modified later in the program. For example:
```
const int x = 5;
```
Here, the value of x is 5 and cannot be changed later in the program.
"static" is used to declare a variable or function that has a local scope and lifetime but retains its value between function calls. For example:
```
void foo() {
static int count = 0;
count++;
cout << count << endl;
}
```
Here, the variable "count" is declared as static within the function "foo". Each time the function is called, the value of "count" will be retained and incremented by 1.
It is also worth noting that "const static" can be used together to declare a constant variable with internal linkage. This means that the variable can only be accessed within the same translation unit (i.e. the same source file). For example:
```
const static int x = 5;
```
阅读全文