Hi all,
I have a rather basic C/C++ question about the priority of the ++ operator in regard to pointers. Note the following code (joining two strings):
#define LENGTH 255
void mystrcat (char *base, char *add) {
while(*base) ++base;
while( *(base++) = *(add++) );
}
int main() {
char name[LENGTH]="Feline";
char lastname[LENGTH]=" Hazard";
mystrcat(name,lastname);
printf("My name is: %s", name);
return(0);
}
Now the function mystrcat joins lastname to name but I don't understand exactly why. At the end of the 1st while loop (line 3) base should be pointing to the terminal zero (\0) of the base string, right?
Now, the second while loop (line 4) I don't understand. What happens first? The assignment (*base)=(*add)
and the increment of pointer positions? Or the other way around? First increment of position, and then assignment. I don't quite understand the prioritizing of actions in the 4th line.
Thanks,
-FH