#include
int main(int argc, char *argv[]) {
char s[]=\"help\";
printf(\"%d\",strlen(s));
}
Why the above output is 4, isn
strlen()
does not count the number of characters in the array (in fact, this might not even be knowable (if you only have a pointer to the memory, instead of an array). It does, as you have found out, count the number of characters up to but not including the null character. Consider char s[] = {'h','i','\0','t','h','e','r','e'};