I read this on the internet that an array variable points to the first element of an array. The example of the code is given below :
#include <stdio.h>
int main()
{
int i,a[10];
for ( i = 0; i <= 9; ++i )
{
printf ("The address of the array element %d is = %p\n",i+1, &a[i]);
}
printf ("The address of the &a is = %p\n", &a);
printf ("The address of &a[0] is = %p\n", &a[0] );
printf ("The address of a is = %p", a);
return 0;
}
according to the internet source : The array variable a and the array element a[0] both have the same address because the array variable name a points to the first element of the array, i.e. a[0]. My question is :
- Is the array variable a a pointer, since it's pointing to the first element of the array?
If the array variable a is a pointer, then shouldn't the address of the pointer a and the variable a[0] (to which the pointer a is pointing) differ? (here we get the same address)
If the array variable a is not a pointer then how shall we explain the code given below?
a[0] = *a
a[1] = *a+1
a[2] = *a+2
a[3] = *a+3
a[4] = *a+4
a[5] = *a+5
I suppose this is a very long question but please, do tell me the answer as I have wrecked my mind over this and now I want to beat my head against the wall. Also I am new to stack overflow.