In the K&R C Programming book, I came across this code snippet for string copying:
/* strcpy: copy t to s; pointer version 3 */
void strcpy(char *s, char *t)
{
while (*s++ = *t++)
;
}
This correctly copies two character arrays (of course it does). My question is, why does it work the way it does? There doesn't seem to be any condition checking inside the while. There is an assignment and a post increment. My gut feeling is that this always evaluates to true (similar to how while(1) always evaluates to true, and we need a break somewhere to get out of the loop.
There is nothing inside of the loop either. No bound checking, no ifs, nothing. It all seems very risky and reckless to me. Can someone walk me through this? Thanks.