“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”
does is to copy the destination string’s characters to the source string (here ‘d’ to ‘c’). In the above statement, one after another, the contents being pointed to by the destination pointer (’d') are faithfully copied into the source string, pointed to by (’c').
Then the while condition is evaluated, which works on a boolean basis (TRUTH/FALSITY). In C, a true value is non-zero and false value is ‘0′.
So, until the source string (’d') hits the end of the string, ‘
The loop will be executed until d reaches a null character
string copy
string copy utill zero appears
String copy is performed indeed but be careful with the space allocated for the destination string.
Check this example:
char s1[10]=”abcde”;
char s2[3];
char* c,*d;
c=s2;
d=s1;
while(*c++ = *d++);
printf(”%s - %sn”,s1,s2);
The code is string copy. But it does not add a null pointer to the end. There should also be a check for overlapping addresses.
Where is a logical value being returned in the while(*c++ = *d ++)
*c++ = *d++ is not a logical expression, hence incorrect syntactically.
Isn’t it. Please correct me if i’m wrong.
String copy–for sure
All that the basic operation :
while (*c++ = *d++)
;
does is to copy the destination string’s characters to the source string (here ‘d’ to ‘c’). In the above statement, one after another, the contents being pointed to by the destination pointer (’d') are faithfully copied into the source string, pointed to by (’c').
Then the while condition is evaluated, which works on a boolean basis (TRUTH/FALSITY). In C, a true value is non-zero and false value is ‘0′.
So, until the source string (’d') hits the end of the string, ‘