argc
is 5.
This program checks each pair of consecutive arguments and counts how many are substrings of each other (either the first is a substring of the second or vice versa):
bcd abcd // i = 2
abcd ab // i = 3, good
ab abc // i = 4, good
In this case, since i=3
and i=4
fit the criteria, k
is 7.
Breaking down the code, the innermost for loop exits if there is a different character or if one string ends. The line if (!*p || !*q) k += i;
increases k
only if one of the strings hit the end.