At least my compiler absolutely does not compile this as C code. Even a C++ compiler comments this with "error C2601: "distance": Local function definitions are invalid".
int main(void)
{
int distance(char a[], char b[])
{
...
}
}
Actually, the function distance should be above main() and should then be called in main() with valid parameters.
int main(void)
{
char a[] = { ... , 0 };
char b[] = { ... , 0 };
int x = distance(a, b);
return 0;
}
The result is either -1, 0 or -3. The value of res is never calculated, because len2 is never incremented.
Presumably all values in the two arrays should also be compared, which is not realized in the code above. I would never recommend the peculiar negative index loop.
for (int j = 1 - len1; j <= 0; ++j)
if (a[-j] != b[-j])