http://blog.csdn.net/zdcsky123/article/details/6517811
I believe a lot of C beginners know that the array name is equivalent to a pointer to the first address of the array, and the function name is equivalent to the function pointer, pointing to the function's entry address. Now again, if the name of the group to take the address, then what will get it? A lot of people immediately think: to the pointer to address, is the pointer of pointers, both two-level pointers! Of course, this conclusion is wrong, otherwise this note will be meaningless.
Let's step through the analysis, here is a code to verify the problem
Code:
- #include <stdio.h>
- int Main ()
- {
- int a[10];
- printf ("a:/t%p/n", a);
- printf ("&a:/t%p/n", &a);
- printf ("a+1:/t%p/n", a+1);
- printf ("&a+1:/t%p/n", &a+1);
- return 0;
- }
You can compile and run it, and the result of my output is:
Code:
- /*
- A:0012ff20
- &a:0012ff20
- A+1:0012ff24
- &a+1:0012ff48
- */
A and &a point to the same piece of address, but they have a different effect after +1, a+1 is the memory size of an element (increase 4), and &a+1 increases the memory size of the entire array (40 increase). Both A and &a point and &a[0] are the same, but the properties are different!
Read here, a lot of friends have already understood the mechanism, if still somewhat vague, please continue to look down
Code:
- int Main ()
- {
- int a[10];
- printf ("%d/n", sizeof (a));
- return 0;
- }
This code will output the memory size of the entire array, not the size of the first element, so whether we are contacted, sizeof (a) where A and
&a some similarities?! Yes, yes, &a is the address of the entire array! Both the array name fetch address is equivalent to the logarithmic group fetch address.
Well, let's summarize, if you still don't understand, don't worry, the following concepts are clear
In fact a and &a results are the first address of the array, but their type is not the same.
A is &a[0], that is, the first element of the array takes the address, a+1 represents the first address +sizeof (element type).
&a Although the value is an array of the first element address, but the type is: type (*) [number of array elements], so the &a+1 size is: The first address +sizeof (a).
There is the wrong conclusion of the pointer of the first reference of this article, in fact, even if you do not understand the above, it should be judged that the conclusion is wrong, you should know that the array name is the first address of the array at the same time, it should be known that the array name is only "quite" to the pointer, not really a pointer, The array name is just a constant (a constant value for the address of the first element of the group), so the + + or--operation cannot be performed. But the constant is unable to take address, and the reason why there is &a, in fact, the meaning of a here is not the original number of the group name, it represents the entire array.
The C language array name and the address of the logarithm group name