char * my_char
*ptr = &my_char
*a.p
: Due to the priority, it equals to *(a.p)
, it first evaluates a.p and then dereference that arrow(*a).p
: it first deference a and then evaluates p in a, it can be simplied as a->b
int**
: pointer to an integer pointerconst int x = 3;
const int *p = &x;
, in this case we can’t directly revise the value the pointer points by pointers, but we can change where p points.*p = 4;
is illegalp = &y;
is legalint * const p = &x;
, in this case we can modify the value address &x stores but we can’t revise where p points.*p = 4;
is legalp = &y;
is illegalconst int * const p = &x;
Typical misunderstanding:
1
2
3
int x = 4;
const int *p = &x;
x = 4;
This operation is legal, because the two declaration of pointer and variable does not conflict with each other and we don’t try to use pointer p to modify where it points.
And the next is an illegal example:
1
2
3
const int x = 4;
int * q = &x;
*q = 5;
In this case the two declaration conflicts with each other and the complier will print errors.
array[3][5]
:array[0]+1
will refer to array[0][1]
array+1
will refer to array[1][0]