Look at the code first:
1#include <stdio.h>2 3 intMainvoid)4 {5 intI= About;6 int*p = &i;7p[0] = the;8printf"What's in it?%d\n", p[0]);9printf"What's ' s ' i ' now?%d\n", i);Ten return 0; One}
Look at the results again:
What's in it? 88
What's ' s ' I ' now? 88
That is, when you point the pointer p to the memory address of I, the behavior of P can behave like an array.
Assigning a value to P[0] is a number 88 for that address and three contiguous memory units behind it.
Because the int type occupies 4 bytes, and one memory unit corresponds to one byte.
The value of I is also the same address, that is, the address of p[0], so the value of I is rewritten.
If you assign a value of p[1], the value of I does not change. But actually assigning a value to P[1] Returns a segment error.
* It is estimated that the memory address is not allowed to write. But the compiler will not find this error.
Array and pointers to BDSM