is that char null terminator is including in the length count

后端 未结 5 1851
春和景丽
春和景丽 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 06:06

    It's 4.

    strlen() counts the number of characters up to, but not including, the first char with a value of 0 - the nul terminator.

提交回复
热议问题