void strcpy(char *s, char *t)
{
while ((*s++ = *t++) != '\0');
}
and
void strcpy(char *s, char *t)
{
while (*s++ = *t++);
}
are the same, what does this mean? what does removing the condition do?
void strcpy(char *s, char *t)
{
while ((*s++ = *t++) != '\0');
}
and
void strcpy(char *s, char *t)
{
while (*s++ = *t++);
}
are the same, what does this mean? what does removing the condition do?
The expression *s++ = *t++
still has a result, and that result that can be used as a condition. More precisely, the result will be the character copied, and as you (should) know all non-zero values are considered "true", and as you also (should) know strings in C are zero terminated.
So what the loop does is copy characters until the string terminator is reached.
Its checking if the end of string \0
NUL
is reached or not, while copying the value of *t
to *s
and then incrementing both the pointers.
And to answer your 2nd question, consider this,
What is the difference between
if(a != 0)
&
if(a)
Its just two ways of writing the same code. The only difference that i can think of is code clarity. The first one is more verbose, its easier to read, understand and maintain.