Possible Duplicate:
How does “while(*s++ = *t++)” work?
I had the following question during an interview. Can someone please explain it to me?
void question( char *s, char *t)
{
while (*s++ = *t++);
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Copies the string, pointer by
tto the memory, pointed bys.operator=will return the assigned value.tis supposed to point to aNULL-terminated string andsshould point to memory, large enough to store that string.So, the
whileloop will stop when\0is hit, which is the end of the string, pointed byt. During thiswhileloop, all chars (different from\0) intwill be copied intos.Expanded a little, it’s the same as: