问题 单项选择题

以下程序的输出结果是( )。
#include <stdio.h>
#include <string.h>
main()
char str[12]='s','t','r','i','n','g';
printf("%d\n",strlen(str) );

A.6

B.7

C.11

D.12

答案

参考答案:A

解析: 本题考查求字符串的长度。程序中定义字符串str时中请了12个字节的内存空间,对它赋初值后,函数strlen在求串长度时,以'\0'作为串结束符,所以,strlen(str)的值为6。

单项选择题
单项选择题