is that char null terminator is including in the length count

后端 未结 5 1838
春和景丽
春和景丽 2020-12-24 05:37
#include 

int main(int argc, char *argv[]) {
   char s[]=\"help\";
   printf(\"%d\",strlen(s));  
}

Why the above output is 4, isn

5条回答
  •  春和景丽
    2020-12-24 05:59

    strlen counts the elements until it reaches the null character, in which case it will stop counting. It won't include it with the length.

提交回复
热议问题