#include
int main(int argc, char *argv[]) {
char s[]=\"help\";
printf(\"%d\",strlen(s));
}
Why the above output is 4, isn
strlen(const char* ptr)
returns the length of the string by counting the non-zero elements starting at until reaches zero. So '\0'
doesn't count.
I recommend that you consult the reference like link for questions like this.
It's clearly stated as:
A C string is as long as the number of characters between the beginning
of the string and the terminating null character (without including the
terminating null character itself).