C programming arrays and pointers

Arrays and Pointers in C

Pointers and Arrays are kind of similar in C programming. As we all know that array is a collection of items of similar data types. And the items in an array are stored in contagious memory locations in computers memory heap. Now if an array is declared like:

int a[5];

Now in above declaration of the array, if the first element of array a[0] is stored at memory location 0x16 (say) then the second element a[1] of array will be stored at the memory location adjacent to it which is 0x16 as integer occupies 4 bytes of memory.

In computers memory, it would look like

In C programming, the name of an array always points to the base address i.e above a will refer to the address 0x12. So &a[0] and ‘a’ are equal.

That is why arrays and pointers are analogous in many ways.

Relation between array and pointer

Consider following declaration

int *p;
int a[5];
p = a;

Now in above declaration

&a[0] is equivalent to pointer variable p and a[0] is equivalent to *p