单选题有以下程序:#include #include struct A{ 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.1f,a.a,a.b,a.c);}void f(struct A t){ t.a=1002; strcpy(t.b,ChangRong); t.c=1202.0; return t;}程序运行后的输出结果是( 

题目
单选题
有以下程序:#include #include struct A{ 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.1f,a.a,a.b,a.c);}void f(struct A t){ t.a=1002; strcpy(t.b,ChangRong); t.c=1202.0; return t;}程序运行后的输出结果是(  )。
A

1001,ZhangDa,1098.0

B

1002,ChangRong,1202.0

C

1001,ChangRong,1098.0

D

1002,ZhangDa,1202.0


相似考题
更多“有以下程序:#include <stdio.h>#include <string.h>struct A{ int a; ”相关问题
  • 第1题:

    以下程序的运行结果是

    #include "stdio.h"

    main()

    {struct date

    {int year,month,day;}today;

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

    }

    A.6

    B.8

    C.10

    D.12


    正确答案:A

  • 第2题:

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

  • 第3题:

    有以下程序: include struct STU (char name[10]; int num; };

    有以下程序: #include <string.h> struct STU (char name[10]; int num; }; void f(char *name, int num) {struct STU s[2]={{"SunDan",20044}.{"Penghua",20045}}; num=s[0].num; strcpy(name,s[0].name); } main() {struct STU s[2]={{"YangSall",20041},{"LiSiGao",20042}},*p;p=&s[1]; f(p->name,p->num); printf("%s%d\n",p->name,p->num); } 程序运行后的输出结果是 ______。

    A.SunDan 20042

    B.SunDan 20044

    C.LiSiGuo 20042

    D.YangSan 20041


    正确答案:A
    解析:本题主函数中定义了结构体类型的指针变量p,并使其指向了结构体类型的数组s[1],并通过调用函数f改变了指针变量p所指向的结构体中成员变量name的值,但并未改变其num的值。这是因为函数f中的形参name是一个字符型指针变量,它指向了主函数中指针变量p所指向的结构体的成员变量name,所以对函数f中的形参*name的改变也就是刘主函数中p->name的改变,而函数f中对形参num的改变并不会影响主函数中p->num的值,因为此时传递给num的是一个值,而不是地址。

  • 第4题:

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

  • 第5题:

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

  • 第6题:

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

  • 第7题:

    有以下程序#include "stdio.h"main(){ struct date { int number; float fenzhi; char name; }stu; printf("%d\n",sizeof(stu));} 程序的运行结果是A.3 B.5C.7 D.8


    正确答案:C
    本题主要考查结构体所占存储单元的计算。在C语言中,函数sizeof的作用是用以计算变量所处存储单元的大小,即占的字节数。
    在本题中,程序首先定义了一个结构体,该结构体包含三个成员变量,分别为整型、浮点型和字符型。在C语言中,这三种类型的变量所占的字节数分别为2、4、1,然后定义一个该结构体的结构体变量,并输出该结构体变量所占的字节数。那么结果应为2+4+1=7,因此本题正确的答案为C。

  • 第8题:

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

  • 第9题:

    有以下程序 include include int fun(int n) {int *

    有以下程序 #include <stdio.h> #include <stdlib.h> int fun(int n) {int *p; p=(int*)malloc(sizeof(int)); *p=n; return *p; } { int a; a=fun(10); printf("%d\n",a+fun(10)); } 程序的运行结果是______。

    A.0

    B.10

    C.20

    D.出错


    正确答案:C
    解析:malloc(sizeof(int))的作用是开辟一个长度为sizeof(int)存储空间,并通过强制类型转换(int*)将此存储空间的地址赋给了—个整型的指针变量p。然后执行语句“*p=n”,使得*p的值为10,并通过返回此值,在主函数中输出a+10的值,即输出20。

  • 第10题:

    有以下程序:include include main(int argc,char *argv[]){ int i,len=0;f

    有以下程序: #include <stdio.h> #include <string.h> main(int argc,char *argv[]) { int i,len=0; for(i=1;i<argc;i+=2)len+=strlen(argv[i]); prinff("%d\n",len); } 此程序经编译链接后生成的可执行文件是ex.exe,若运行时输入以下带参数的命令行: ex abed efg h3 k44则执行后的输出结果时( )。

    A.14

    B.12

    C.8

    D.6


    正确答案:D
    解析:main函数可以有两个参数,第一个参数为一个整型变量,表示命令行参数的个数,本题为5;第二个参数为一个字符型指针数组,其中第一个数组元素指向程序名,第二个数组元素指向命令行中的第一个参数,以后依此类推。由程序中的for循环可以看出,程序是求第一(argv[1])、第三(argv[3])个参数的长度之和,即4+2=6。

  • 第11题:

    以下程序的输出结果是() includemain(){ union un{int i; long k; char c;};struct by

    以下程序的输出结果是( ) # include<stdio.h> main() { union un{int i; long k; char c; }; struct byte{ int a; long b; union un c; } r; printf("%d\n",sizeof(r)); }

    A.10

    B.13

    C.7

    D.8


    正确答案:A

  • 第12题:

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

  • 第13题:

    以下程序的输出结果是()includemain(){struct stru{int a,b:char c[6];}:printf("%d\n

    以下程序的输出结果是 ( ) #include<stdio.h> main() {struct stru{int a,b: char c[6]; }: printf("%d\n",sizeof(stru)), }

    A.2

    B.4

    C.8

    D.10


    正确答案:D

  • 第14题:

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

  • 第15题:

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

  • 第16题:

    下列程序的运行结果为【】。 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。

  • 第17题:

    下列程序的输出结果是( )。 include main() { struct st { int y,x,z; }; union {long

    下列程序的输出结果是( )。 #include <stdio.h> main() { struct st { int y,x,z; }; union { long i; int j; char k; } un; printf("%d,%d\n",sizeof(struct st),sizeof(un)); }

    A.6, 2

    B.6, 4

    C.8, 4

    D.8, 6


    正确答案:B
    解析:本题主要考查结构体和联合内存使用的区别:结构中不同的成员分别使用不同的内存空间,一个结构所占内存空间的大小是结构中每个成员所占内存空间大小的总和,结构中每个成员相互独立;联合所占用的内存空间为最长的成员所占用的空间。

  • 第18题:

    有以下程序:includestruct tt{int x;struct tt*y;}*p;struct tt a[4]={20,a+1,15,a+2,

    有以下程序: #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[4]的初始化中,相当于将其生成为一个链表,故打印两次相当于将前两个整数值打印出来.因此选项D是正确的。

  • 第19题:

    以下程序的输出结果是【】。 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。

  • 第20题:

    有以下程序 include int fun(int a, int b) { if(b==0) return a;

    有以下程序 #include <stdio.h> int fun(int a, int b) { if(b==0) return a; else return(fun(-a,-b)); } main() { printf("%d\n",fun(4,2)); } 程序的运行结果是______。

    A.1

    B.2

    C.3

    D.4


    正确答案:B
    解析:在调用一个函数的过程中又出现直接或间接调用该函数本身,称为函数的递归调用。本题考查的是函数递归调用。首先当a=4,b=2时,调用fun(4,2),不满足条件b==0,继续调用fun函数;此时a=3,b=1,即调用fun(3,1),不满足条件b=0,继续调用fun函数;此时a=2,b=0,满足条件b=0,返回a的值2。

  • 第21题:

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

  • 第22题:

    下列程序的运行结果为()。includemain(){struct date {int year,month,day; }today; pr

    下列程序的运行结果为( )。 #include<stdio.h> main() { struct date {int year,month,day; }today; printf("%d\n",sizeof(struct date)); }

    A.8

    B.6

    C.10

    D.12


    正确答案:B
    解析:解答本题需要注意两个知识点;①结构体变量的长度是其内部成员长度的总和,本题中,structdate中包含year、month、day这3个整型变量,一个整型变量占2个字节:②sizeof是求所占字节数的运算符。

  • 第23题:

    有以下程序:include struct STU{char name[10]; int num;};void f1(struct STU c){ st

    有以下程序: #include <stdio.h> struct STU { char name[10]; int num; }; void f1(struct STU c) { struct STU b={"LiSiGuo",2042}; c=b; } void f2(struct STU *c) { struct STU b={"SanDan",2044}; *c=b; } main() { struct STU a={"YangSan",2041}, b={"WangYin",2043}; f1(a); f2(&b); printf("%d%d\n",a.num,b.hum); } 执行后的输出结果是( )。

    A.2041 2044

    B.2041 2043

    C.2042 2044

    D.2042 2043


    正确答案:A
    解析:f2函数传递的是变量的地址,可以实现数据的交换,而f1函数传递的是值,调用完f1函数后,c的值改变了,但main函数中的a值并未改变。

  • 第24题:

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

    A.# include [string.h]

    B.# include {math.h}

    C.# include(stdio.h)

    D.# include<stdio.h>


    正确答案:D