Const modifier variable
in C,aconst -Modified variable is read-only, essentially a variable, and the modified variable takes up space in memory (that's nonsense), which is inherently const only useful to compilers, Useless at run time. the const and type Order are not required, the generic type is before, andtheconst is behind.
The const- modified array is read-only and the decorated array space cannot be changed.
const int* p; P variable, pointing to content is immutable
int const* p; P variable, pointing to content is immutable
int* Conse p; P is immutable,p points to content variable
Const int* Const p//p and p point to immutable content
Formula: Left digit right finger
when const appears to the left of the * number, the data pointed to by the pointer is constant
The pointer itself is constant when const appears to the right of the * number
Const modifier function parameters and return values
The const modifier function parameter indicates that the value of the parameter is not expected to change in the body of the function, andtheconst indicates that the return value is immutable and is used to return the pointer.
const int * FUNC ()
{
static int count = 0;
count++;
Return &count;
}
Volatile can be interpreted as "compiler warning indicator word"
Used to tell the compiler that every time a variable value is removed from memory, it is used primarily to decorate variables that may be accessed by multiple threads, or to modify variables that may be changed by unknown factors. If a variable is an rvalue for a long time, it is easily replaced with a constant.
Const and violate