How does this C copy function break out of the loop?
void copy (char *source, char *dest) {
while (*dest++ = *source++);
}
The char that is presented *source
is copied to the field *dest
it points to. For the next iteration, each char pointer points to the next field in memory, is that correct?
When does this cycle actually stop? The only condition I can think of is that there is no room in memory, but then the function should fail, right?
I'm completely new to C, so forgive me the simple questions.
+3
source to share
3 answers
Your interpretation of the copy is correct. The loop stops when what dest points to zero, i.e. The "\ 0" character. See http://en.wikipedia.org/wiki/Null-terminated_string
+1
source to share