C++ 常量指针和矩阵

Remember that an array is just like a constant pointer

As in the case of arrays, the compiler allows the special case that we want to initialize the content at which the pointer points with constants at the same moment the pointer is declared:

 
const char * terry = "hello"; 



In this case, memory space is reserved to contain "hello" and then a pointer to the first character of this memory block is assigned to terry. If we imagine that "hello" is stored at the memory locations that start at addresses 1702, we can represent the previous declaration as:

 
It is important to indicate that terry contains the value 1702, and not 'h' nor "hello", although 1702 indeed is the address of both of these.

The pointer terry points to a sequence of characters and can be read as if it was an array (remember that an array is just like a constant pointer). For example, we can access the fifth element of the array with any of these two expression:

1 2 
*(terry+4)
terry[4]



Both expressions have a value of 'o' (the fifth element of the array).

Available online at: http://www.cplusplus.com/doc/tutorial/

原文地址:https://www.cnblogs.com/zxwAAA/p/3327140.html