Const in C Language
Const in C language indicates "unchangeable variable", or can be a "pseudo constant"
Const in C ++ is called a constant with type descriptions.
Const int liv_num = 10; liv_num = 18; // error because liv_num is modified by const, it cannot be directly assigned a value.
So why do I say "pseudo constants"?
We know that there are two ways to assign values to variables in c: direct assignment and indirect assignment.
For the first method, we have verified that it is not possible. So, can the liv_num value be changed by indirect assignment?
Note: it must be a. c file. If it is. cpp, it will not work, because const in c ++ is called "a constant with type description".
# Include
# Include
Int main () {// define a constant const int liv_num = 10; // liv_num = 18; // error because liv_num is modified by const, it cannot be directly assigned a value. // define a pointer to the constant const int * pliv_num = & liv_num; // convert the pointer pointing to a constant to int * pNum = (int *) pliv_num; // assign the value * pNum = 20; printf (liv_num = % d, liv_num ); // result: 20 system (pause); return 0 ;}
Through the above, we will direct the const to "pseudo constant" in c, which also shows a problem. The const is saved in the "stack". If you want to verify it, you can use debug, observe the memory.