For starters these function declarations
void sh1(char dest[], char src[]);
and
void s2(char * dest, char *src);
are equivalent because function parameters declared like arrays are adjusted to pointers to objects with types that corresponds to the array element types.
You even can include in one compilation unit the both declarations of a function with the same name and they will declare the same one function (though the function definition must be one provided that the function is not an inline function).
So the question is about whether the expressions used in the loops that is
while(dest[i++]=src[i++]);
and
while(*dest++=*src++);
yield the same result.
The first loop has undefined behavior. You should rewrite it like
while(dest[i] = src[i]) i++;
As for example dest++
increases the pointer it can be rewritten like dest = dest + 1
. Thus applying the operator ++ several times to the pointer you will get that it is equivalent to the expression dest = ( dest + 1 ) + 1 + ... +1;
Ot it can be written like dest = dest + i;
where i
is the sum of 1 + 1 ...+ 1
So for each iteration of the loops these expressions
*dest++
and dest[i], i++
yield the same result.