有以下程序#include <stdio.h>#include <string.h>main( ){ printf("%d\n",strlen ("ATS\n012\1") ); }程序运行后的输出结果是A)3B)8C)4D)9

题目

有以下程序

#include <stdio.h>

#include <string.h>

main( )

{ printf("%d\n",strlen ("ATS\n012\1") ); }

程序运行后的输出结果是

A)3

B)8

C)4

D)9


相似考题
参考答案和解析
正确答案:B
【答案】B
【知识点】strlen()函数以及反义字符的考察
【解析】strlen()函数的功能是求得字符串长度,反义字符\n与\1各表示一个字符,所以结果是B。
更多“有以下程序#include &lt;stdio.h&gt;#include &lt;string.h&gt;main( ){ printf("%d\n",strlen ( ”相关问题
  • 第1题:

    以下4个程序中,完全正确的是()。A.include main(); {/* programming */ printf("progr

    以下4个程序中,完全正确的是( )。

    A.#include <stdio.h> main(); {/* programming */ printf("programming!\n");}

    B.#include <stdio.h> main() {/*/ programming /*/ printf("programming!\n");}

    C.#include <stdio.h> main() {/*/* programming */*/ printf("programming!\n");}

    D.#include <stdio.h> main() {/* programming */ printf("programming!\n");}


    正确答案:B
    解析:选项A在定义main()函数时,函数头后面多了一个分号,故选项A不正确;C语言中的注释是不能嵌套的,故选项C不正确:选项D在使用预编译指令#include时漏掉了#号,所以也是错误的。故应该选择B。

  • 第2题:

    有以下程序include.main(){char*p="abcde\ofghjik\0";printf("%d\n",strlen(p));} 程

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

    A.12

    B.15

    C.6

    D.5


    正确答案:D
    解析:本题首先定义了一个字符型指针变量p,并用一个宇符串给它赋值,然后调用printf()函数输出p所指向的字符串的长度。字符串的结束标记为“\0”,其长度为“\0”前的字符个数,故长度为5。所以4个选项中D正确。

  • 第3题:

    有以下程序:includeincludemain(){char str[][20]={"Hello","Beijing"},*P

    有以下程序: #include <stdio.h> #include <string.h> main() { char str[][20]={"Hello","Beijing"},*P=str[0]; printf("%d\n",strlen(p+20)); } 程序运行后的输出结果是( )。

    A.0

    B.5

    C.7

    D.20


    正确答案:C
    解析:本题考查字符数组和指针的运用。strlen是测试字符串长度的函数,函数的值为字符串的实际长度,不包括'/0'在内。str[][20]={"Hello","Beijing"}定义了一个2行20列的数组,数组的首地址是&str[0][0],p+20是从首地址向后移了20位,指针指向了str[1][0]处,此时求字符串的长度,是从str[1][0]开始的,即“Beijing”的长度,所以输出结果是7。

  • 第4题:

    以下4个程序中,完全正确的是A.include main(); {/*programming*/ printf("programming

    以下4个程序中,完全正确的是

    A.#include<stdio.h> main(); {/*programming*/ printf("programming!\n");}

    B.#include<stdio.h> main() {/*/programming/*/ printf("programming!\n");}

    C.#include<stdio.h> main() {/*/*programming*/*/ printf("programming!\n")}

    D.include<stdio.h> main() {/*programming*/ printf("programming!\n");}


    正确答案:B
    解析: 选项A)main();的分号是错误的,不能有分号;选项C)的注释语句多了两个*号;选项D)include前面没有#。

  • 第5题:

    以下四个程序中,完全正确的是______。A.include main(); {/*programming*

    以下四个程序中,完全正确的是______。

    A.#include <stdio.h> main(); {/*programming*/ printf("programming!\n");}

    B.#inc lude<stdio.h> main() {/*/programming/*/ printf("programming!\n");}

    C.#include <stdio.h> main() {/*programming*/ printf("programming!\n");}

    D.include<stdio.h> main() {/*/*programming*/*/ printf("programming!\n");}


    正确答案:C
    解析:C程序中注释用“/*”和“*/”括起来,它可以出现在程序中任何合适的地方。选项A中“main();”是—个函数声明语句,下面的大括号及其内容作为—个语句块,应放在程序的大括号中,故选取项A错误;选项B中的注释语句不正确,因为程序在编译时认别到两次“/*”作为注释的开始,但为识别到“*/”作为注释的结束,故选项B错误;选项 D的“include”前缺少“#”,故选项D错误。

  • 第6题:

    以下四个程序中,完全正确的是()

    A.#include <stdio.h> main(); {/*/ programming /*/ printf("programming!n");}

    B.#include <stdio.h> main() {/* programming */ printf("programming!n"); }

    C.#include <stdio.h> main() {/*/* programming */*/ printf("programming!n"); }

    D.include <stdio.h> main() {/* programming */ printf("programming!n"); }


    B 在选项A中,main()函数后面的分号是错误的,C语言在函数名后而不能有分号。在C语言中注释内容必须放在”/’和”+/”之间,”/”和”*/”必须成对出现,按语法规定在注释之间不可以再嵌套”/∥’和”+/”。在选项C的程序段中注释语句之间有嵌套;所以选项C不正确。C语言用#inc1ude命令行来实现文件包含的功能。#inc1ude命令行的形式为:#inc1ude”文件名”,所以存选项D中inc1ude前面少了一个#符号,因而选项D不正确。