Give yourself a wave of self-dismissal ~
Introduce pointer constants and constant pointers first
const int *p; This is a pointer constant int const* p; This is a constant pointer.
Const is a constant modifier, and the modifier is a constant, and the characteristic of a constant is that it cannot be changed.
The pointer constants are introduced first,
const int *p; int i=2; p=&i;
Here *p is a constant, his value can not be changed, that is, no longer through the *p=1; This assigns a value to change the value of I , but can be directly i=1, so change the value of I, at this time the value of *P also changed accordingly to 1
int const* P=null;int I=1;
p=&i;
A constant pointer, as the name implies, can be assumed to be a constant, a constant pointer must be assigned only once, the value of the pointer cannot be changed and then the assignment will be error, but the first assignment of NULL, let it become a null pointer is allowed, because the null pointer is very special. The value of *p can be changed
There's a place to watch.
#include <stdio.h>int main () {const int i=10;int *p;p= (int *) &i;*p=100;printf ("%d\n", I); return 0;}
This program, in some compilers can change the value of I , and some cannot ... Look at the situation, but in C + + is certainly not allowed to change, should be directly error
The previous introduction of pointer constants and constant pointers is to introduce the following array names, from this article to the thought https://zhuanlan.zhihu.com/p/24799071?iam=83d196fe2b966cf160601b3be0de2003 &utm_source=com.tencent.tim&utm_medium=social
... In fact, I still do not understand, it means that the array name is not a pointer constant, because the official definition of the array does not have a const modifier, I give my own understanding
If the array name is a pointer constant, why is it not possible to do a ++,--operation?
The array itself is a type, so the array name is not a pointer
When the content operation is performed, the array name is implicitly converted to a pointer//implicit conversion, like Char str=97, and%c outputs str, which gives a, like
The two-dimensional array recursion, in fact, is the element type is an array of arrays//a bit around, but thinking about this, look at the ability to understand the logical thinking of individuals, anyway I do not understand (ノ ̄д ̄) Dentetsu
On the left and right values of pointers, here's a simple
int a = 10,b;int *d;d = &a; D is on the left, which represents the memory address of the pointer variable that stores d. b = *d; D is on the right, indicating that D represents the memory address of the storage variable A. *d is getting the value of a in the A memory address.
C language, array name, pointer constant, and constant pointer