bc8o8 |
03-24-2006 10:13 AM |
The lines
Code:
===snip===
exp_array+=sizeof(int *);
===snip===
exp_array-=sizeof(int *);
===snip===
are incrementing your array location by sizeof(int *) which (on my system) is 4. So you are skipping valid locations and reading/writing other areas in memory. What you want to do instead is actually just increment the pointer -- pointers are smart enough to know their size, so it will increment appropriately.
For example the following should do what you want
Code:
for (i=0; i<10; i++)
{
*exp_array=i;
exp_array++;
}
int j;
for (j=10;j>0;j--)
{
printf("%i \n",*exp_array);
exp_array--;
}
although, instead of moving your exp_array pointer around, a better approach would be to just use exp_array[ i ] = i; and either printf("%i \n",exp_array[ i ]); or printf("%i \n",exp_array+i); (which are identical)
|