Recently I have been reading a book on C language in depth. I feel that the relationship between pointers and arrays is quite understandable. Sometimes someone writes a long article about pointers and arrays. Intuition tells me that it is a good article. It must be the result of years of practice and deliberation by the expert. If I can reach the level he understands, then my C language will take another step. But in order to have a profound understanding, I will not read his article, but I will first think about it myself.
Int a [5] = {0, 1, 2, 3, 4}
Int * p1 = a; // define p1 as the first address pointing to the first element of array a, instead of the address pointing to array a. Although the value is the same, the meaning is different.
A + I is not equal to & a + I
A + I = a + I * sizeof (a [0]) and & a + I = a + I * sizeof ()
The running result of the following program is? Www.2cto.com
# Include <stdio. h>
# Include <stdlib. h>
Int main ()
{
Int a [5];
Int * p1 =;
Int * p2 = &;
Printf ("% p \ n", );
Printf ("% p \ n", a + 1 );
Printf ("% p \ n", & a + 1 );
System ("PAUSE ");
Return 0;
}
The running result on my machine is: 0022FF20
0022FF24
0022FF34
From regecode