有以下程序: #include <string.h> main() {char *p="abcde\Ofghjik\0"; printf("%d\n",strlen(p)); } 程序运行后的输出结果是( )。

admin2010-01-10  19

问题 有以下程序:    #include  <string.h>    main()    {char *p="abcde\Ofghjik\0";    printf("%d\n",strlen(p));    }    程序运行后的输出结果是(  )。

选项 A、12
B、15
C、6
D、5

答案8

解析 本题首先定义了一个字符型指针变量p,并用一个字符串给它赋值,然后调用printf()函数输出p所指向的字符串的长度。由于字符串的结束标记为、0,其长度为第1个\0前的字符个数,故长度为5。所以4个选项中D正确。
转载请注明原文地址:https://kaotiyun.com/show/HHWp777K
0

最新回复(0)