K
karthikbalaguru
Hi,
In the below code, the subtraction of 4 causes subtraction of
8. Strange !
int main(void)
{
static int x[] = {100,200,300,400,500};
int i, *p;
p = &x[4]-4;
for(i=0;i<=4;i++)
{
printf("%d \n",*p);
p++;
}
}
The output is
100
200
300
400
500
But, how does p = &x[4]-4 gets evaluated to
point to the first element of the array x.
Shouldn't it point to 3rd element (x[2]) of
the array x ?
How can i actually deduct 4 and make it to
point to x[2] (3rd element of array) ?
Any ideas ?
Thx in advans,
Karthik Balaguru
In the below code, the subtraction of 4 causes subtraction of
8. Strange !
int main(void)
{
static int x[] = {100,200,300,400,500};
int i, *p;
p = &x[4]-4;
for(i=0;i<=4;i++)
{
printf("%d \n",*p);
p++;
}
}
The output is
100
200
300
400
500
But, how does p = &x[4]-4 gets evaluated to
point to the first element of the array x.
Shouldn't it point to 3rd element (x[2]) of
the array x ?
How can i actually deduct 4 and make it to
point to x[2] (3rd element of array) ?
Any ideas ?
Thx in advans,
Karthik Balaguru