First, a is an array of 10 int s. This is the easy part.
p1 is a "pointer to int ". You assign it the value &a[0] . This takes the address of the first element a . So p1 now points to the first element of a .
p2 also a "pointer to int ". You assign a directly to him. In this case, the standard conversion should take place with an array-to-pointer conversion. In principle, an array can be converted to a pointer to its first element. You assign the result of this transformation p2 . Thus, p2 also a pointer to the first element of a .
p3 is a "pointer to an array of 10 int ". You take the address of array a and assign it to this pointer. So, now this pointer points to the array itself (and not to its first element).
You might think: "Well, the first element has the same address as the array, so what's the difference?" In fact, you will notice the difference when you try to increase the pointer. An increment of either p1 or p2 will give you a pointer to the second element of the array. The increment p3 will give you a pointer to the next array of 10 int (which does not actually exist).
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐ │ int │ int │ int │ int │ int │ int │ int │ int │ int │ int │ └─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘ ^ └── p1, p2, p3
So, if you start with the directions you described, and then increase them, you get:
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬┄ │ int │ int │ int │ int │ int │ int │ int │ int │ int │ int │ └─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴┄ ^ ^ └── p1, p2 └── p3
source share