Const difference study notes

Eight usages of const in C++ programming_哔哩哔哩_bilibili

const first modifies the left side of const, if there is nothing on the left, then modifies the thing on the right

The first two a and b are not pointers. Since they are modified int, they are types, so the values ​​of a and b cannot be changed

The pointer of the type of c, const is modified by int, so c can point to other addresses, but the value inside cannot be modified

First of all, the const of c is modified by *, which cannot point to constants, because pointing to pointers just cannot point pointers to other things, rather than changing internal values 

const is modified in front of the type, that is, A is a constant, and the pointed object cannot be changed, but the value in the internal address of the object can be changed

 

volatile is to declare that A is volatile, and not to declare that the value of A does not change


If applied to a function:

 

Then the members in the function must all be of const type 

 

Guess you like

Origin blog.csdn.net/qqQQqsadfj/article/details/132409692