is that char null terminator is including in the length count

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

    strlen: Returns the length of the given byte string not including null terminator;

    char s[]="help";
    strlen(s) should return 4.
    

    sizeof: Returns the length of the given byte string, include null terminator;

    char s[]="help";
    sizeof(s) should return 5.
    

提交回复
热议问题