Const and volatile

Const : Constant, the size cannot be changed while the program is running, that is, it cannot become an lvalue. But the value stored in memory can be modified through a pointer

When const is on the left side of *, the data itself is a constant.
When const is on the right side of *, the pointer is a constant.

The formula is to count from the left and point to the right

const is used to modify functions, and is generally used to modify function return values ​​that cannot be changed. That is

const int *func();   //在 * 号的左侧

The volatile
compiler warning directive warns the compiler to fetch the value of a variable from memory every time. It
mainly modifies variables that may be accessed by multiple threads, such as values ​​that will be changed by hardware interrupts.

Guess you like

Origin blog.csdn.net/weixin_45950842/article/details/115303739