Read the comments please.
Code:
#include <stdio.h>
int main(void)
{
int array[10] = { 0,1,2,3,4,5,6,7,8,9};
int* arrayPtr = NULL;
int i;
/* Let's say that I want to access the 5th */
/* element of my array, by setting a pointer */
/* at the first element and then do pointers */
/* arithmetic */
/* Set the pointer to first element */
arrayPtr = array;
/* Increment the pointer until we reach the 5th */
/* element. Do it with a loop.
/* Extremely careful with the conditions of the */
/* loop or you go out of bounds */
for( i = 0 ; i < 4 ; i++)
{
arrayPtr++;
}
/* Not the pointer is set to the 5th element */
/* For test let change the value of 5th element to 124 */
*arrayPtr = 124;
/* Print the whole array */
for( i = 0 ; i < 10 ; i++)
{
printf("%d\n",array[i]);
}
return 0;
}
Hope this helps