the address of the array is contained in the array name that is a pointer to the array it means when we are declaring an integer array a[5] we are getting 10 bytes for the array elements and two bytes for the pointer a?
means 12 bytes are occupied in fact
is it so and i just want to confirm to store a address(pointer variable) how many bytes we require is it 2 bytes?

if you have a[10]

a refers to the address of the first element of the array
so you will have 10 * sizeof(int) bytes occupied by the array.

There can be array of ponters.Since a pointer variable always contain an address,an array
of pointers would be nothing but a collection of addresses.The addresses present in the array of pointers can be addresses of isolated variables or addresses of array elements
or any other address.All rules that apply to an ordinary array of pointers as well.I think a program would clarify the concept.

main()
{
int *arr[4];    /*array of integer pointers*/
int i=31,j=5,k=19,l=71,m;


arr[0]=&i;
arr[1]=&j;
arr[2]=&k;
arr[3]=&l;


for(m=0;m<=3;m++)
printf("%d",*(arr[m]));
}

Edited 3 Years Ago by happygeek: fixed formatting

This article has been dead for over six months. Start a new discussion instead.