答案来源:https://zhidao.baidu.com/question/187071815.html

对于字符数组str[N],判断方法有以下三种:

  • 第一种:用库函数strlen

1
len = strlen(str); // 数组长度
  • 第二种:利用计数器

1
2
int i=0;
while(str[i++] != '\0'); // 数组str的长度为i
  • 第三种:利用sizeof函数

1
len = sizeof(str)/sizeof(str[0]); // 数组长度

对于其他类型的数组,都可以用字符数组的第三种方法,第三种方法是通用的。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
  • 2021-06-23
  • 2021-05-09
  • 2022-02-08
  • 2022-01-03
  • 2021-07-31
猜你喜欢
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案