Question Details

No question body available.

Tags

c pointers

Answers (2)

January 25, 2026 Score: 6 Rep: 411,793 Quality: High Completeness: 80%

Whenever you're unsure about pointers, my recommendation is to draw them using pen and paper.

If we draw your variables we will have something like:

+------------+      +---------------+---------------+-----+-----------------------------+
| personarr | ---> | personarr[0] | personarr[1] | ... | personarr[noOfPersons - 1] |
+------------+      +---------------+---------------+-----+-----------------------------+

That is, personarr points to the first element of an array of noOfPersons elements.

When you use the pointer-to operator & on personarr you get a pointer to personarr itself:

+-------------+      +------------+      +---------------+---------------+-----+-----------------------------+
| &personarr | ---> | personarr | ---> | personarr[0] | personarr[1] | ... | personarr[noOfPersons - 1] |
+-------------+      +------------+      +---------------+---------------+-----+-----------------------------+

I hope this helps you understand what's going on.


To draw &personarr[0] too, it's this:

+------------+            +---------------+---------------+-----+-----------------------------+
| personarr | ------+--> | personarr[0] | personarr[1] | ... | personarr[noOfPersons - 1] |
+------------+       |    +---------------+---------------+-----+-----------------------------+
                     |
+----------------+   |
| &personarr[0] | --/
+----------------+

Now for the types, there's really a very simple and almost generic rule: When you use the pointer-to operator & you add an asterisk to the type.

For your case since person_arr is the type struct Person then &personarr becomes struct Person .

For &personarr[0] it's really the same: Because personarr[0] has the type struct Person then &personarr[0] is of the type struct Person .


And lastly about pointers and arrays, their differences and their relationship.

A great deal of confusion for beginners is because an array can decay to a pointer to its first element.

Lets take this simple example code to help explain:

void f(int p)
{
    // In here the variable p is a pointer, there's no information about what
    // it really points to. It is, in essence, a pointer to a single int value.
}

int main(void) { // Define an array of four elements int a[4] = { 1, 2, 3, 4 };

// Call the function defined above, passing a pointer to the first element f(a);

// The above call is exactly equal to this f(&a[0]); }

When using the array name in the call f(a) then it decays to a pointer to its first element, and is therefore the same as f(&a[0])

You can of course pass an actual pointer to the function f as well:

int main(void)
{
    // Define an array of four elements
    int a[4] = { 1, 2, 3, 4 };

// Same as int p = &a[0]; int p = a;

f(p); }

Now for the reason that we can use both pointers and arrays for indexing, it's because of this decay. In fact, for any array or pointer x and index i, the expression x[i] is exactly equal to (x + i). If x is an array it's really (&x[0] + i).

So even if all we have is a pointer, and not the array itself, we can still use array indexing using the pointer. But, and this is important, once an array has decayed to a pointer (to the first element of the array) then the size information of the array is lost. If you use the sizeof operator on a pointer, you get the size of the pointer itself, not any possible array it might point to (because the compiler doesn't know it points to the first element of an array).

Example:

int main(void)
{
    // Define an array of four elements
    int a[4] = { 1, 2, 3, 4 };

// Same as int p = &a[0]; int p = a;

// Should print 16 on all systems where int is four bytes (generally all PC systems today) printf("size of array: %zu\n", sizeof(a));

// Should print 4 on 32-bit systems, and 8 on 64-bit systems printf("size of pointer: %zu\n", sizeof(p));

}

And finally a major difference between pointers and arrays: When you apply the pointer-to operator & to them they result in different things.

Using a and p from the examples above, &a is a pointer to the array, and has the type int ()[4], while &p is a pointer to the pointer variable and has the type int .

However, the pointer to the array and the pointer to its first element will be equal (that is ((void ) &a) == ((void ) &a[0]), but of different types. &a is int ()[4], while &a[0] is int .

Finally a bit of curiosity: Because of the commutative property of addition, the expression (a + i) is the same as *(i + a) which leads to a[i] and i[a] being the same as well. This even works with fixed indexes, so a[2] and 2[a] is the same. But please don't use this in real code.

January 25, 2026 Score: 4 Rep: 152,804 Quality: Medium Completeness: 70%

The answer to your question is:

  • Yes, the address of an array is the address of its first element. Similarly, the address of a structure in memory is the address of its first member (provided this member is not a bitfield).

Note however that your code is confusing:

  • printf("Address pointed by personarr: %p\n", (void*)&personarr); is inconsistent: personarr is a pointer to struct Person objects and it does indeed point to enough space to store noOfPersons such items. Yet you should not use & address of operator to pass the address pointed to by personarr, you should just write:

    printf("Address pointed by personarr: %p\n", (void*)personarr);