Pointer to pointer issue
I created a pointer-to-pointer and an int array. But when I try to access
the array via my pointer-to-pointer it skips some elements and move by
from two elements.
e.g. from 1 to 3
Here is my code:
int main(void) {
int c=10;
int p[5]={2,3,5,6,8};
int *x;
int **y;
x=p;
y=&p;
printf("p value is %d and p points to %d",p,&p);
printf("\n x is %d \n",x[1]);
printf("\n y is %d \n",y[0]);
return 0;
}
When I print y[1] it will print 5 instead of 3 and y[2] is printed as 8.
I cant think of the reason. can any one help me on this. Pointer x is is
working fine, and move along the correct elements as x[0]=2,x[1]=3,x[5]=5.
No comments:
Post a Comment