我有道C语言题目~有兴趣请做做~以下程序的输出结果是( ).main(){ char st[20]= “hello\0\t\\\”;printf(%d %d \n”,strlen(st),sizeof(st));A) 9 9 B) 5 20 C) 13 20 D) 20 20

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/09 11:27:53
我有道C语言题目~有兴趣请做做~以下程序的输出结果是( ).main(){ char st[20]= “hello\0\t\\\”;printf(%d %d \n”,strlen(st),sizeof(st));A) 9 9 B) 5 20 C) 13 20 D) 20 20

我有道C语言题目~有兴趣请做做~以下程序的输出结果是( ).main(){ char st[20]= “hello\0\t\\\”;printf(%d %d \n”,strlen(st),sizeof(st));A) 9 9 B) 5 20 C) 13 20 D) 20 20
我有道C语言题目~有兴趣请做做~
以下程序的输出结果是( ).
main()
{ char st[20]= “hello\0\t\\\”;
printf(%d %d \n”,strlen(st),sizeof(st));
A) 9 9 B) 5 20 C) 13 20 D) 20 20

我有道C语言题目~有兴趣请做做~以下程序的输出结果是( ).main(){ char st[20]= “hello\0\t\\\”;printf(%d %d \n”,strlen(st),sizeof(st));A) 9 9 B) 5 20 C) 13 20 D) 20 20
strlen()函数用来计算字符串数组的长度.它包含再库中.
这个长度代表字符串中以\0为结束符前面的字符数.
“hello\0\t\\\”可以分解位{'h','e','l','l','o','\0',.}
'h','e','l','l','o'共5个字符
strlen(st)的值为5.
sizeof()函数用来统计参数所占的内存空间,即字节数.因为数组st[20]是字符型的,每一个数组元素占据一个字节,数组共20个元素.
所以sizeof(st)的值是20.
编译不过的原因有两个:
1、如前所述strlen函数调用应该包含头文件
所以应该添加#include
2、printf(%d %d \n”,strlen(st),sizeof(st));
这句差一个" 当然编译不过.
修改成printf("%d %d \n”,strlen(st),sizeof(st));
最后修改的代码应该是:
#include
#include(可以省略)
main()
{ char st[20]= “hello\0\t\\\”;
 printf(“%d %d \n”,strlen(st),sizeof(st));
}
另外提供一篇关于sizeof()和strlen()详细解释的文章.
链接如下: