C inner product function without using array subscripting As part of a question designed to help us understand the relationship between pointers and arrays in C, I've been asked to write an inner product function that doesn't use any array subscripting. Here's what I came up with, but it looks like the kind of complicated 'clever' coding that we've traditionally been told NOT to write. 
Any feedback on it, or how it could be done better / more efficiently would be much appreciated.

int inner_product(const int *a, const int *b, int n) {

    const int *p, *q;
    int result = 0;
    for(p = a, q = b; p &lt; a + n, q &lt; b + n; p++, q++) {
            result += *p * *q;
    }
    return result;
}


Edit - Inner product is simply summing the product of the indexes, so a[1,2,3] b[2,3,4] would be 1*2 + 2*3 + 3*4
I have a few comments on style.  (By which I really mean, 100% opinion... :D)



One declaration per line

A lot of people strongly disagree with this, but I find it much easier to read code that has one declaration per line.

const int *p;
const int *q;


Is a lot clearer to me than:

const int *p, *q;


Though really, the only time I've vehemently opposed to it is if both variables are not the same in terms of a pointer or value:

const int *p, q;


Is a harder to read and more prone to errors than:

const int *p;
const int q;




n

I would name the n paramter something more meaningful.  I would consider calling it size or num.

It's fairly apparent that n is meant to be the number of elements, but two or three extra keystrokes seems worth the extra clarity.



Possible implementation

I would probably write the function something like this:

int inner_product(const int *a, const int *b, int num)
{

    const int* end = a + num;

    int sum = 0;

    while (a != end) {
            sum += (*a) * (*b);
            ++a;
            ++b;
    }

    return sum;

}


Since the two pointers are incremented at the same time, there's no reason to check both.

This should be a tiny bit more efficient (well... probably not once the compiler does it's magic optimisations on the original), and I think it's a bit clearer.