Xiangzhong-com

函数strlen()和sizeof的区别:

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#define SENTENCE "It is a cat"

int main()

{

    char name[40];

    gets(name);

    printf("%s\n", name);

    printf("The size of name is %zd %d\nThe size of  SENTENCE is %zd %d",strlen(name), sizeof(name), strlen(SENTENCE), sizeof(SENTENCE));//请注意strlen()和sizeof的区别!

return 0;

}

strlen()函数是计算实际字符串的长度,而sizeof不但计算了字符串的大小,还记算了字符串末尾不可见的空字符!

 

分类:

技术点:

相关文章:

  • 2021-10-15
  • 2021-12-10
  • 2021-06-21
猜你喜欢
  • 2021-08-04
  • 2021-08-18
  • 2022-01-13
  • 2021-10-16
  • 2021-09-02
相关资源
相似解决方案