I’m looking at some existing code and added a few printf lines. There’s a string cp “TZ=test”
cp = strchr(str, '=');
printf("Text: %s\n",cp);
printf("Text cp+1: %s\n",cp+1);
*cp = '\0';
printf("Text: %s\n",cp);
printf("Text cp+1: %s\n",cp+1);
the output is:
Text: =test
Text c+1: test
Text:
Text c+1: test
I understand the first two tests but why does the fourth one print “test” even though *cp was set to ‘\0’ right before?
Unlike some other languages, C doesn’t know what string is, it only knows where it ends, so it prints from the pointer that you give it.