niusouti.com

单选题有以下程序:#include #include typedef struct{ char name[9]; char sex; float score[2];} STU;void f(STU a){ STU b={zhao,'m',85.0,90.0}; int i; strcpy(a.name, b.name); a.sex = b.sex; for(i=0; i<2; i++) a.score[i]=b.score[i];}main(){ STU c={Qian,'f',95.0, 92.0};

题目
单选题
有以下程序:#include #include typedef struct{ char name[9]; char sex; float score[2];} STU;void f(STU a){ STU b={zhao,'m',85.0,90.0}; int i; strcpy(a.name, b.name); a.sex = b.sex; for(i=0; i<2; i++) a.score[i]=b.score[i];}main(){ STU c={Qian,'f',95.0, 92.0}; f(c); printf(%s,%c,%2.0f,%2.0f, c.name, c.sex, c.score[0], c.score[1]);}程序的运行结果是(  )。
A

Qian,f,95,92

B

Qian,m,85,90

C

Zhao,f,95,92

D

Zhao,m,85,90


相似考题
参考答案和解析
正确答案: A
解析:
结构体作为函数参数时是传值调用。本题中,函数传递的是实参结构体变量中的值。函数体内对形参结构体变量中任何成员的操作都不会影响对应实参中成员的值。因此,f函数没有任何实际作用。答案选择A选项。
更多“有以下程序:#include <stdio.h>#include <string.h>typedef struct{ c”相关问题
  • 第1题:

    有以下程序 include typedef struct { int num;double s; }REC; void funl(REC *x) { x

    有以下程序 include<stdio.h> typedef struct { int num;double s; }REC; void funl(REC *x) { x->num=23;x->s=88.5; } void main() { REC a={16,90.0}; fun1(&A); printf("%d\n",a.num); } 程序运行后的输出结果是( )。


    正确答案:23
    23

  • 第2题:

    以下程序的输出结果是()includeincludemain(){char str[12]={'s','t','r',

    以下程序的输出结果是( ) #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

  • 第3题:

    有以下程序 include include typedef struct { cha

    有以下程序 #include <stdio.h> #include <string.h> typedef struct { char name[9]; char sex; float score[2]; } STU; STU f(STU a) { STU b={"Zhao", 'm', 85.0, 90.0}; int i; strcpy(a.name, b.name); a.sex = b.sex; for (i=0; i<2; i++) a.score[i] = b.score[i]; return a; } main() { STU c={"Qian", T, 95.0, 92.0}, d; d=f(c); printf("%s,%c,%2.0f,%2.0f\n", d.name, &sex, &score[O], d.score[1]); } 程序的运行结果是

    A.Qian, f,95,92

    B.Qian,m,85,90

    C.Zhao,m,85,90

    D.Zhao,f,95,92


    正确答案:C
    解析:本题的f()函数中,首先定义了一个STU结构体变量b并初始化为{"Zhao",'m',85.0,90.0},然后分别通过strcpy()库函数、赋值语句和for循环,将b中所有成员分别赋给形参a的相应成员,最后返回a。所以,无论传递给函数fun()的参数是什么,结果返回的都会是函数中定义的STU结构体b的内容{"Zhao",'m',85.0,90.0}。故最终输出结果为:Zhao,m,85,90,应该选择C。

  • 第4题:

    有以下程序:include include main( ) {char a[ 7 ] = "a0 \0a0 \0";int i,

    有以下程序:#include <stdio.h>#include <string.h>main( ) { char a[ 7 ] = "a0 \0a0 \0"; int i,j; i = sizeof(a); j = strlen(a); printf(" % d %d \n" ,i,j); }程序运行后的输出结果是( )。

    A.22

    B.76

    C.72

    D.62


    正确答案:C
    解析:C语言.中以,'\0'作为字符串的结束符,且strlen函数计算的是,'\0',字符前的所有字符的个数,故本题中strlen(a)应为2。数组定义以后系统就为其分配相应大小的内存空间,而不论其中有没有内容。sizeof运算符是计算变量或数组所分配到的内存空间的大小,所以本题的sizeof(a)为7。

  • 第5题:

    以下程序的输出结果是【】。 include main() {struct stru {int a; float b; char d[4]; }

    以下程序的输出结果是【 】。

    include<stdio.h>

    main()

    { struct stru

    { int a;

    float b;

    char d[4];

    };

    printf("%d\n",sizeof(struct stru));

    }


    正确答案:10
    10 解析:结构体变量占用内存空间的字节数是结构体各分量占用内存空间的字节数的总和。int型变量占用2字节,float型变量占用4字节,char型占用1字节,char d[4]是含有4个元素的char型数组,占用4字节。sizeof(struct stru)是计算结构体变量占用内存空间的字节数,2+4+4=10。

  • 第6题:

    有以下程序 include struct st { int x,y;} data[2]={1,10,2,20}; main(

    有以下程序 #include <stdio.h> struct st { int x,y;} data[2]={1,10,2,20}; main() { struct st *p=data; printf("%d,",p->y); printf("%d\n",(++p)->x); } 程序的运行结果是______。

    A.10,1

    B.20,1

    C.10,2

    D.20,2


    正确答案:C
    解析:本题定义了一个包含两个元素(data[0]、data[1])的结构体数组data,其中data[0].x=1;data[0].y=10;data[1].x=2; data[1].y=20。在主函数中,定义了一个指向结构体数组的结构体指针变量p,使得p指向结构体数组的首地址,所以p->y访问的是第一个鲒构体数组元素的第二个值,即data[0].y;(++p)->x访问的是第二个结构体数组元素的第一个值,即 data[1].x,所以程序输出结果为10,2。

  • 第7题:

    有如下程序段#include "stdio.h"typedef union{ long x[2]; int y[4]; char z[8];}atx;typedef struct aa { long x[2]; int y[4]; char z[8];} stx;main(){ printf("union=%d,struct aa=%d\n",sizeof(atx),sizeof(stx));}则程序执行后输出的结果是A.union=8,struct aa=8 B.union=8,struct aa=24C.union=24,struct aa=8 D.union=24,struct aa=24


    正确答案:B
    本题主要考查结构体和联合体所占的存储空间。
    在本题程序中,首先定义了一个联合体,联合体中具有三个成员,它们的类型分别为长整型、整型和字符型。按照C语言的规定,这三种类型的变量所占的存储空间分别为4个字节、2个字节和1个字节。但由于定义的成员都是数组,长整型数组的大小为2,那么需要的总空间为8个字节;整型数组的大小为4,那么需要的总空间为8个字节;字符数组的大小为8,需要的总空间也为8个字节,因此,可以看出三个成员需要的存储空间一样,都为8。根据联合体变量中的所有成员共享存储空间,联合变量的长度等于各成员中最长的长度的特点,我们可知,系统只需为该联合体变量准备8个字节存储空间即可。
    然后,定义了一个结构体,结构体中的成员类型及数组大小与联合体完全一致,即三个成员所需的空间都为8个字节。但是结构体与联合体不一样的是,结构体不能共享空间,一个结构体变量的总长度是各成员长度之和。因此,该结构体所需的存储空间为24个字节。
    综上所述,我们可以知道程序中的联合体和结构体所需要的存储空间分别为8个字节和24个字节。因此,用sizeof运算符计算这两者的存储空间,输出的结果应该为union=8,struct aa=24,本题正确答案选B。

  • 第8题:

    下列程序的输出结果是()。 include include main() {char a[]="\n123\\";pr

    下列程序的输出结果是( )。 #include<stdio.h> #include<string.h> main() { char a[]="\n123\\"; printf ("%d,%d\n",strlen(a),sizeof(a)); }

    A.5,6

    B.5,5

    C.6,6

    D.6,5


    正确答案:A
    解析:转义字符'\n'表示换行,'\\'表示反斜杠,函数strlen()是计算字符串的长度,不包括文件结束标志('\0'),函数sizeof()统计字符串所占的字节数。

  • 第9题:

    下面程序的输出结果是 ( ) include include { char * p1="abc" , *

    下面程序的输出结果是 ( ) # include<stdio.h> # include<string.h> { char * p1="abc" , * p2=" ABC ",str[50]="xyz"; strcpy(str+2.strcat (pi,p2)); printf("%s\n",str);}

    A.xyzabcAB

    B.zabcABC

    C.yzabcABC

    D.xycbcABC


    正确答案:D

  • 第10题:

    以下程序 include include main() { char*p1="abc",*p2="ABC",str[50]="xy

    以下程序 #include<stdio.h> #include<string.h> main() { char*p1="abc",*p2="ABC",str[50]="xyz"; strcpy(ar+2,strcat(p1,p2)); printf("%s\n",str); } 的输出是______。

    A.xyzabcABC

    B.zabeABC

    C.yzabcABC

    D.xyabcABC


    正确答案:D
    解析:strcat(p1,p2)将字符串abcABC防到了*p1所指向的存储单元中:strcpy在本题将abcABC复制到str+2所指向的存储单元中,即覆盖原str数组中的字符z及其后的所有字符,故str的值为“xyabcABC”。

  • 第11题:

    在下列# include命令中,正确的一条是 ( )

    A.# include [string.h]

    B.# include {math.h}

    C.# include(stdio.h)

    D.# include<stdio.h>


    正确答案:D

  • 第12题:

    有以下程序:includeincludetypedef struct{char name[9];char sex;float s

    有以下程序: #include <stdio.h> #include <string.h> typedef struct{char name[9];char sex;float score[2]}STU; STU f(STU A) {STU b={"Zhao",'m',85.0,90.0}; int i; strcpy(a.name,b.namC) ; a.sex=b.sex; for(i=0;i<2;i++) a.score[i]=b.score[i]; return a; } main() {STU c={"Qian",'f',95.0,92.0},d; d=f(C) ; pintf("%s,%c,%2.of.%2.of\n",d.name,d.sex,d.score[0],&score[1]); } 程序的运行结果是( )。

    A.Qian,f,95,92

    B.Qian,m,85,90

    C.Zhao,m,85,90

    D.Zhao,C95,92


    正确答案:C
    解析:本题的f()函数中,首先定义了一个STU结构体变量b并初始化为{"Zhao",'m',85.0,90.0},然后分别通过strcpy()库函数、赋值语句和for循环,将b中所有成员分别赋给形参a的相应成员,最后返回a。所以,无论传递给函数fun()的参数是什么,结果返回的都会是函数中定义的STU结构体b的内容{"Zhao",'m',85.0,90.0}。故最终输出结果为:Zhao,m,85,90;应该选择C。

  • 第13题:

    有以下程序:includeincludemain(){char a[]={'a','b','c','d','e','f','g'

    有以下程序: #include <stdio.h> #include <string.h> main() { char a[]={'a','b','c','d','e','f','g','h','\0'}; int i,j; i=sizeof(a); j=strlen(a); printf("%d,%d\n",i,j); } 程序运行后的输出结果是( )。

    A.9,9

    B.8,9

    C.1,8

    D.9,8


    正确答案:D
    解析:sizeof是求字节运算符,在字符数组a中,“\0”也作为字节保存,是a数组的一个成员,所以sizeof(a)的值应为9;strlen是测试字符串长度的函数,函数的值为字符串中的实际长度,不包括“\0”在内,所以strlen(a)的值为8。

  • 第14题:

    有以下程序 include struct tt { int x; struct tt *y; } *p; s

    有以下程序 #include <stdio.h> struct tt { int x; struct tt *y; } *p; struct tt a[4]= {20,a+ 1,15,a+2,30,a+3,17,a}; main() { int i; p=a; for(i=1; i<-2; i++) { printf("%d,", p->x ); p=p->y; }

    A.20,30,

    B.30,17

    C.15,30,

    D.20,15,


    正确答案:D
    解析:题目中定义了一个全局结构体数组a,结构体中包含两个成员:一个int型变量x和一个自身类型指针y。所以,结构体数组a的初始化列表中每两个初始化一个结构体元素。主函数通过一个for循环,连续调用了两次输出函数printf(),每次输出p所指元素的x成员值。p初始化时指向数组 a的首地址,即a[0]的位置,所以第1次输出的值为20。然后又将a[0]的成员y的值赋给p,y在初始化时是a+1,所以p在第2次输出时指向的元素是a[1],故第2次输出的值为15。所以本题最终输出结果是“20,15,”,应该选择D。

  • 第15题:

    下列程序的运行结果为【】。 include include {int a; char b[10]; double c;};

    下列程序的运行结果为【 】。

    include<stdio.h>

    include<string.h>

    { int a; char b[10]; double c; };

    void f (struct A *t);

    main()

    { struct A a={1001,"ZhangDa",1098.0};

    f(&a) ; printf("%d,%s,%6.lf\n",a.a,a.b,a.C);

    }

    void f(struct A*t)

    { strcpy(t->b, "ChangRong");}


    正确答案:1001ChangRong1098.0
    1001,ChangRong,1098.0 解析:本题主要考查结构体变量赋初值,刚一开始给a赋值1001,b数组什"zhangDa",c赋值1098.0,由于被调函数中引用了结构体成员b,因此在使用strcpy时,strcpy(字符数组1,字符串2),作用是将字符串2复制到字符数组1中, b数组变成了"ChangRong",所以在最后输出时,结果为:1001,ChangRong,1098.0。

  • 第16题:

    有以下程序: include include struct NODE {int num;struct NODE *next; }

    有以下程序:

    #include <stdio.h>

    #include <stdlib.h>

    struct NODE

    { int num;

    struct NODE *next;

    };

    main()

    { struet NODE *p,*q,*r;

    int sum=0;

    p=(struct NODE *) malloc(sizeof(struct NODE));

    q=(struct NODE *) malloc(sizeof(struet NODE));

    r=(struct NODE *) malloc(sizeof(struct NODE));

    P- >num=1;q- >num=2;r->num=3;

    p- >next=q;q- >next=r;r- >next=NULL;

    sum + =q- >next- >num;sum + =P- >num;

    printf("%d\n",sum);

    }

    执行后的输出结果是( )

    A.3

    B.4

    C.5

    D.6


    正确答案:B
    解析:程序中q->next=r,所以q->next->num即为r->num,值为3,而p->num=1,所以sum=3+1=4。

  • 第17题:

    有以下程序#include "stdio.h"main(){ struct date {int year,month,day;}today; printf("%d\n",sizeof(struct date));}程序的运行结果是A.6 B.8C.12 D.10


    正确答案:A
    本题考查结构体类型所占用的内存字节数。结构体占用的内存字节数为各个成员变量所占内存字节数的总和。题目中给出了一个结构体date,里面包括3个整型的成员变量,在Turbo C中,每个整型变量占用2个字节的内存,这3个整型变量总共占用6个字节的内存。sizeof函数是返回对象所占内存的大小。要注意,对于不同的编译器,同样类型的变量所占的内存字节数不同,C语言的默认编译器为Turbo C。

  • 第18题:

    以下程序:includeincludemain(){char str[]="abcd\n\123\xab";printf("%d"

    以下程序: #include<stdio.h> #include<string.h> main() {char str[]="abcd\n\123\xab"; printf("%d",(str)); } 运行后的输出结果是( )。

    A.10

    B.9

    C.7

    D.14


    正确答案:C

  • 第19题:

    下面程序的运行结果是 ( ) include include main( ) { char * a="

    下面程序的运行结果是 ( ) # include<stdio.h> # include<string.h> main( ) { char * a="AbcdEf",* b="aBcD" a + +;b + +; printf("%d\n",strcmp(a,b)); }

    A.0

    B.负数

    C.正数

    D.无确定值


    正确答案:C

  • 第20题:

    有以下程序: include include void f(char * s,char*t){char k; k=*s;*s=*

    有以下程序: #include <stdio.h>#include <string.h>void f(char * s,char*t){ char k; k=*s; *s=*t; *t=k; s++; t--; if( * s) f(s,t);}main( ){ char str[10] :"abedefg", * p; p = str + strlen(str)/2+1; f(p,p -2); printf( "% s \n" ,str);程序运行后的输出结果是( )。

    A.abcdefg

    B.gfedcba

    C.gbcdefa

    D.abedcfg


    正确答案:B
    解析:本程序的作用是将字符串str倒序。语句p=str+strlen(str)/2+1;将指针变量p指向字符'e'所在的存储单元,P-2指向字符,'c'所在的存储单元,在函数f中将这两个存储单元的内容交换,然后将f函数中指向字符'e'的指针变量s加1,指向字符'c'的指针变量t减1,继续将s和t指向的存储单元的内容进行交换,直到s指向的存储单元的内容为空为止。所以本题程序输出的结果是字符串"abcdefe”的倒序形式"gfedcba"。

  • 第21题:

    有以下程序 include include typedef stmct{ char name[9];char sex;flo

    有以下程序

    #include <stdio.h>

    #include <string.h>

    typedef stmct{ char name[9];char sex;float score[2];}STU;

    void f(STU a)

    { STU b={"Zhao",'m',85.0,90.0}; int i;

    strcpy(a.name,b.name) ;

    a.sex=b.sex;

    for(i=0;i<2;i++) a.score[i]=b.score[i];

    main( )

    { STU c={"Qian",'f',95.0,92.0};

    f(c);printf("%s,%c,%2.0f,%2.0f\n",c.name,c.sex,c.score[0],c.score[1]) ;

    }

    程序的运行结果是

    A.Qian,f,95,92

    B.Qian,m,85,90

    C.Zhao,f,95,92

    D.Zhao,m,85,90


    正确答案:A
    解析:本题考查的是函数调用时的参数传递问题。程序在调用函数f时,传给函数f的参数只是结构变量c在栈中的一个副本,函数f的所有操作只是针对这个数据副本进行的修改,这些都不会影响变量c的值。

  • 第22题:

    有以下程序:include include main(){char *p[10]={"abc","aabdfg","dcdbe"

    有以下程序: #include <stdio.h> #include <string.h> main() { char *p[10]={"abc","aabdfg","dcdbe","abbd","cd"}; printf("%d\n",strlen(p[4])); } 执行后的输出结果是( )。

    A.2

    B.3

    C.4

    D.5


    正确答案:A
    解析:p是由10个指向字符型数据的指针元素组成的指针数组,其中前5个数组元素进行了初始化。p[4]="cd",strlen(str)是统计字符串str中字符的个数(不包括终止符'\0'),输出结果为2。

  • 第23题:

    有以下程序: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。

  • 第24题:

    如果在用户的程序中要使用C库函数中的数学函数时,应在该源文件中使用的include命令是()

    • A、#include〈string.h〉
    • B、#include〈math.h〉
    • C、#include〈stdio.h〉
    • D、#include〈ctype.h〉

    正确答案:B