c语言求数组长度strlen

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c语言求数组长度strlen相关的知识,希望对你有一定的参考价值。

参考技术A strlen 用于计算字符串的长度。
数组长度,应是指数组大小,可存放几个数组元素。
下面例子 计算 float 数组a, char 数组s 的 数组长度,计算s 里字符串长度。
(sizeof 用来计算 变量 和 类型 占内存的大小,单位是字节。)
#include <stdio.h>
int main()
float a[5];
char s[20]="abc123";
int nf,ns,ms;
nf = sizeof(a)/sizeof(float);
ns = sizeof(s)/sizeof(char);
ms = strlen(s);
printf("number of element in a is %d\n", nf);
printf("number of element in s is %d\n", ns);
printf("s string length is %d\n",ms);
return 0;

输出:
number of element in a is 5
number of element in s is 20
s string length is 6

以上是关于c语言求数组长度strlen的主要内容,如果未能解决你的问题,请参考以下文章

c语言中如何求数组长度

c语言数组长度函数

字符串长度怎么算

C语言 数组中字符串的长度的怎么计算的·~就是输入一个字符串怎么能快速的知道他的长度··

C语言数组初始化的问题?为啥我初始化了,数组长度还为0啊,如图

C语言编程,输出指定字符串的长度