计算机二级

有以下程序 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); } 程序运行后的输

题目
有以下程序 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
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

设有如下定义,若要通过px引用rec中的x域,正确的语句()。 struct aa { int x; float y; } rec, *px; px=&rec;

A.px.x;

B.px->x;

C.*px->x;

D.*px.x;


C

第2题:

写出以下程序的执行结果。#include "stdio.h" void f13(int y,int *x) { y=y+*x; *x=*x+y; } int main() { int x=2,y=4; f13(y,&x); printf("%d,%dn",x,y); return 0; }


B B。【解析】由主函数入手,定义了类TestClass的对象s1(2,3),当类对象进入其作用域时调用构造函数,构造函数应该是调用具有参数的“TestClass(inta,intb){x=a;y=b;}”,然后调用成员函数disp,则输出为“cout$amp;

第3题:

请选出以下程序的输出结果()。includesub(int *s,int y){static int t=3; y=s[t];t--;}

请选出以下程序的输出结果( )。 #include <stdio.h> sub(int *s,int y) { static int t=3; y=s[t];t--; } main() { int a[]={1,2,3,4},i,x=0; for(i=0;i<4;i++) { sub(a,x);printf("%d",x); } printf("\n"); }

A.1234

B.4321

C.0

D.4444


正确答案:C
解析:本题考查函数的形参和实参的关系。函数sub将实参x的值传给形参y,y值的改变不能使x的值发生改变,所以输出的x值始终为0。

第4题:

请选出以下程序的输出结果_______。 includesub(int*s,inty){ static int t=3,y=s[t];t

请选出以下程序的输出结果_______。 #include<stdio.h> sub(int*s,inty) { static int t=3, y=s[t];t-; } main() { int a[]={1,2,3,4},i,x=0; for(i=0;i<4;i++){ sub(a,x);printf("%d",x);} printf("\n"); }

A.1234

B.4321

C.0

D.4444


正确答案:C
解析:x作为函数sub()的实参时,函数对x值的改变没有返回主函数,并不能使得x的值变化,所以在打印时,x的值是始终不变的,即为0。

第5题:

下面程序的运行结果是( )。include main(){int a=25; fun(&A); }fun(int *x){ print

下面程序的运行结果是( )。

include<stdio.h>

main()

{int a=25;

fun(&A);

}

fun(int *x)

{ printf("%d\n",++*x);

}


正确答案:26
26 解析:在主函数中只调用了fun函数,调用时把变量a的地址传递给形参。fun函数的形参x是一个指针,其基类型与主函数中a的类型一致,因此在调用时得到的是a的地址,输出项是++*x,*x代表的就是主函数中变量a的存储单元,++*x就是使主函数中a的值加1,输出26。

第6题:

下面程序运行时输出结果为【】。 include include class Rect { public: Rec

下面程序运行时输出结果为【 】。

include<iostream.h>

include<malloc.h>

class Rect

{

public:

Rect(int1,int w)(length=1;width=w;)

void Print(){cout<<"Area:"<<length *width<<endl;)

void *operator new(size-t size){return malloc(size);}

void operator delete(void *p){free(p)

private:

int length,width;

};

void main()

{

Rect*p;

p=new Rect(5,4);

p->Print();

delete p;

}


正确答案:Area:20
Area:20

第7题:

下列程序的输出结果是()。includevoid p(int *x){printf("%d",++*x);}void main(){int

下列程序的输出结果是( )。 #include<stdio.h> void p(int *x) { printf("%d",++*x); } void main() { int y=3; p(&y); }

A.3

B.4

C.2

D.5


正确答案:B
解析:本题考查函数调用时的参数传递。在函数调用时,形参是指向实参的指针变量,则printf的执行结果为3+1=4。

第8题:

有以下程序

include<stdio.h>

typedef struct

{int num;double s;}REC;

void funl(REC x){x.nllm=23;x.s=88.5;}

main( )

{REC a={16,90.0);

funl(A);

prinff(“%d\n”,a.num);

}

程序运行后的输出结果是【 】。


正确答案:16
16 解析:主函数中,通过funl()函数将a值传递给x。但没有把形参x的值返回,此时变量a的值并没有发生变化,所以输出a.hum的值为16。

第9题:

有以下程序

#include <stdio.h>

typedef struct

{ int num;double s ; }REC;

void fun1( REC x ){x.num=23; x.s=88.5;}

main()

{ REC a={16,90.0 };

fun1(a);

printf("%d\n",a.num);

}

程序运行后的输出结果是 【 1 4 】 。


正确答案: