Pointer To Array in C: Pointer Pointing To The Array of Elements
Pointer To Array in C: Pointer Pointing To The Array of Elements
3. We know that array name without subscript points to first element in an array
int a[10];
int a[10][10];
Let
1. x is an array ,
2. i is subscript variable
x [ i ] = * ( x + i )
= * ( i + x )
= i [ x ]
= *x
main()
{
int x[] = {1,2,3,4,5};
int *ptr,i ;
ptr = x
for(i=0;i<5;i++)
{
printf("nAddress : %u",&x[i]);
printf("nElement : %d",x[i]);
printf("nElement : %u",*(x+i));
printf("nElement : %d",i[x]);
printf("nElement : %d",*ptr);
}
}
Output :
Address : 7600
Element : 1
Element : 1
Element : 1
Element : 1
Address : 7602
Element : 2
Element : 2
Element : 2
Element : 2
Address : 7604
Element : 3
Element : 3
Element : 3
Element : 3
Address : 7606
Element : 4
Element : 4
Element : 4
Element : 4
Address : 7608
Element : 5
Element : 5
Element : 5
Element : 5
x[i] *(x + i)
i[x] *ptr
= *( * ( x + i ) + j )