I'm reading K&R and have gotten a bit confused in the character pointers section. K&R provides the following as a version of strcpy with pointers:
void strcpy(char *s, char *t) {
while ( (*s = *t) != '\0') {
s++;
t++;
}
}
How is this different from using a pointer to a single character? Or is C just trusting that I know what I'm doing and both cases use a pointer to a character? It's just that when I have an array of these characters, it's terminated by \0, whereas if it's just a character, the subsequent spots in memory could be anything... is this right?
charis indeed indistinguishable to a pointer to a properly terminated sequence ofchars, aka a string. Tough.sandtabove are indeed pointers to a single character. What else would they be? They're not pointers to strings because C doesn't have strings. Yes, if you happen to have a series of characters in memory ending with a 0, we can do certain string-like things with them.