Alex Rivera | Logout

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

Asked 2009-05-01T04:01:27.130
67

My question is, what does this code do (from http://www.joelonsoftware.com/articles/CollegeAdvice.html):

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

the website says that the code above copies a string but I don't understand why...

does it have to do with pointers?

c
Edit
Report

1 Answer

1

It works by copying characters from the string pointed to by 't' into the string pointed to by 's'. For each character copies, both pointers are incremented. The loop terminates when it finds a NUL character (equal to zero, hence the exit).

answered 2009-05-01T04:09:52.447

Your Answer