Im confused by the line pos = ptr - buffer;

This is used to find the distance from the start of the buffer to the max samp. But as buffer is always essentially the address of the first element, this makes it zero, correct?

So why not use just pos = ptr; ? This in fact makes a compiling error saying something about not being happy to assign a pointer to an unsigned int.

So what is it about the calculation that makes the unsigned int accept a value from two pointers (one being subtracted by the other?)

Code:
double = buffer[1024];
double* ptr = buffer + 1024;
double maxval = 0.0;
unsigned long pos = 0;

while(--ptr >= buffer) {
    if(*ptr >= maxval){
        maxval = *ptr;
        pos = ptr - buffer;
    }
}

printf("the max sample is %f, at pos %d\n",
    maxval, pos);

}