The meaning of const before and after variables and after functions (C++)

 const int * p1=&me;//p1 is variable, *p1 is immutable, and *p1 cannot be used to modify at this time, but p1 can be changed to
 int * const p2=&me;//p2 is immutable, *p2 is variable, here *p2 is allowed to modify its value, but p2 cannot be turned.
 const int *const p3=&me;//p3 is immutable, and *p3 is also immutable. At this time, *p3 cannot be used to modify its value, nor can it be turned to


 A function with const after the function is called a constant member function. A constant member function can be understood as a "read-only" function. It can neither change the value of the data member nor call those member functions that can cause the value of the data member to change. It can only call the const member function.

Guess you like

Origin blog.csdn.net/yc7369/article/details/41967009