How does “while(*s++ = *t++)” copy a string?

It is equivalent to this:

while (*t) {
    *s = *t;
    s++;
    t++;
}
*s = *t;

When the char that t points to is '\0', the while loop will terminate. Until then, it will copy the char that t is pointing to to the char that s is pointing to, then increment s and t to point to the next char in their arrays.

Leave a Comment