arr
and
&arr
always hold the same address (the name of an array is a pointer to array first item, also
&arr[0]
gives the same address).
As for pointer math, the nature (the type) of
arr
and
&arr
is different:
(arr+1)
jumps to the next (the 2
nd) item of the array, while
(&arr+1
) jumps to the end of the array (the compiler takes into account the array size).
Please note your code should be:
#include <stdio.h>
int main()
{
int arr[]={1,2,3};
printf("%p %p\n",arr,&arr);
printf("%p %p\n",arr+1,&arr+1);
return 0;
}
Quote:
can you say me the use of **p? . its confusing. thankz in advance.
A double pointer could be used, for instance, in jagged array implementation:
#include <stdio.h>
#include <stdlib.h>
#define N 3
int main()
{
int ** pp;
int size[N] = { 2,3,1 } ;
pp = (int**) malloc( N * sizeof(int *));
int n,k, count=0;
for (n=0; n<N; ++n)
{
pp[n] =(int *) malloc( size[n] * sizeof(int));
for (k=0; k<size[n]; ++k, ++count)
pp[n][k] = count;
}
for (n=0; n<N; ++n)
{
for (k=0; k<size[n]; ++k)
printf("pp[%d][%d] = %d\n", n, k, pp[n][k]);
printf("-------------\n");
}
for (n=0; n<N; ++n)
{
free(pp[n]);
}
free (pp);
return 0;
}