array question

Im new to C programming and am having trouble understanding the output of this code

int array[]={4,5,8,9,8,1,0,1,9,3};
int *array_ptr;
int main()
{
  array_ptr=array;
  while((*array_ptr) != 0)
    array_ptr++;;
  printf("%d\n", array_ptr - array);
  return(0);
}

the output is 6 but I cant understand how, so will really appreciate if someone explains the logic of this output.

You set the array pointer to the beginning of the array, and then the while loop loops through until one of the array elements is "0". If the first element was "0" then "array_ptr - array" would be 0 (because they both point to the same place in memory). Therefore, if the second element was 0, array_ptr - array = 1. Ergo, if the seventh element of the array was 0, array_ptr - array = 6.

I hope this helps...

This isnt your everday math...this is pointer arithmetic and you can read all about it here.