of the pointerConstThere are two kinds:ConstModifies the object that the pointer is pointing to, or modifies the address stored inside the pointer.
/*** book: "thinkinginc++" * Function: Const's delivery and return address * Time: September 7, 2014 14:11:41* Author: cutter_point*///parameter is non-const type void T (int*) {}// The parameter is a const type of void U (const int* CIP)//CIP is a pointer to the const int data {//! *cip=2; Illegal operation, because the value of CIP point is modified by const, cannot change int i=*cip; Copy value, OK//! int* Ip2=cip; Illegal operation, cannot assign const data to non-const type}//return const type pointer address const char* V () {return "cutter_point--char* V ()";} Returns a const address and a const value of type const int* Const W () {static int i; return &i;} int main () {int x=0; int* ip=&x; Const int* cip=&x; T (IP); //! T (CIP); The const data cannot be assigned to a non-const function u (IP) when the parameter is not evaluated. U (CIP); Because it is a parameter copy mechanism, the const parameter can be given to the const type and non-const type/* If you pass or return an address (a pointer or a reference), it is possible for the client programmer to fetch the address and modify its initial value. If you make this pointer or reference a const, it will prevent the occurrence of such things, the address const return is to return a const pointer can not be assigned to non-const *///! char* cp=v (); The return value of function V () can only be assigned to a const pointer, and the value of the pointer is Const const CHAR* ccp=v (); //! int* ip2=w (); The return value of W () is const const int* const CCIP=W (); Const int* cip2=w (); This is also possible, I am also drunk, C + + really mysterious not to test return 0;}
"Thinkinginc++" 39, Const's delivery and return address