to and from are pointers to characters. When we increment them, we point to the next memory location in each string.
"hello" // a sequence of bytes with a zero marking the end
^-- to
In our loop, we don't need to allocate any helper variables, and can just increment our pointers to point to the next memory slot in each string. I'm not a C expert, so I may get this subtly wrong, but I believe this is equivalent to:
do {
*to = *from; // copy character from source to destination
} while (0 != *to); // until we reach the '\0' terminator
Comments