下列程序的运行结果是( )。 #include<stdio.h> void fun(int*S,int*p) { static int t=3: *

题目

下列程序的运行结果是( )。 #include<stdio.h> void fun(int*S,int*p) { static int t=3: *p=s[t]; t--; } void main { int a[]={2,3,4,5),k; int x; for(k=0,k<4,k++) { fun(a,&x); printf("%d,",x); } }

A.5,4,3,2

B.2,3,4,5

C.2,2,2,2

D.5,5,5,5

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

有以下程序: #include<stdio.h> #include<stdlio.h> void fun(int*pl,int*p2,int*s) { s=(int*)malloc(sizeof(int)); *s=*pl+*p2; free(s); } main( ) { int a=1,b=40,*q=&a; fun(&a,&b,q); printf("%d\n",*q); } 程序运行后的输出结果是( )。

A.42

B.0

C.1

D.41


正确答案:C
Fun函数功能是新开辟内存空间存放a和b的地址,q的地址并没有变化,所以应该还是指向地址a。

第2题:

下列程序的运行结果是()。includevoid fun(int*s,int*p){static int t=3; *p=s[t]; t--

下列程序的运行结果是( )。 #include<stdio.h> void fun(int*s,int*p) { static int t=3; *p=s[t]; t--; } void main() { int a[]={2,3,4,5},k; int x; for(k=0;k<4;k++) { fun(a,&x); printf("%d,",x); } }

A.5,4,3,2

B.2,3,4,5,

C.2,2,2,2,

D.5,5,5,5,


正确答案:A
解析: 分析fun函数程序段,可知fun函数要实现的功能是将s中第(t+1)个元素以前的元素逆置赋给数组p。由于fun中函数定义了静态变量t=3,因此,在主函数中调用函数fun(a,&x)时,就是要将数组a中前4个元素逆置赋给数组x,最后输出x数组。

第3题:

下列程序的运行结果是()。include< iostream.h>void fun (int *a,int*b){int*kk=a;a=b;b=k}void

下列程序的运行结果是( )。 #include< iostream.h> void fun (int *a,int*b) {int*k k=a;a=b;b=k} void main() {int a=2004, b=9,*x=&a,*y=&b; fun(x, y) ; cout<<a<<" "<<b<<endl:}

A.20049

B.92004

C.0

D.编译时出错


正确答案:A

第4题:

有以下程序#include <stdio.h>#include <stdlib.h>int fun(int t){ int *p; p=(int*)malloc(sizeof(int)); *p=t; return *p;}main(){ int a; a = fun(8); printf("%d\n", a+fun(10));}程序的运行结果是A.0 B.10 C.18 D.出错


正确答案:C
本题考查函数的调用。题目给出的程序可以分为两个部分,一个是函数fun,另一个是主函数main。fun函数的功能是输入一个整型变量t,设置一个指向该整型变量的指针p,并将该指针所指向的值返回给main函数。main函数中两次调用了fun函数,第一次变量t的值为8,第二次变量t的值为10,第一次返回值8,使得a=8,第二次返回值10,使得a+fun(10)=18。

第5题:

下列程序的运行结果是()。includevoid fun (int*s,int*p){ static int t=3; *p=s [t];

下列程序的运行结果是( )。 #include<stdio.h> void fun (int*s,int*p) { static int t=3; *p=s [t]; t--; } void main() int a[]={2, 3, 4, 5},k; int x; for(k=0; k<4; k++) { fun (a, &x); printf("%d,", x); }

A.5,4,3,2

B.2,3,4,5,

C.2,2,2,2,

D.5,5,5,5,


正确答案:A
解析:分析fun函数程序段,可知fun函数要实现的功能是将s中第(t+1)个元素以前的元素逆置赋给数组P。由于fun中函数定义了静态变量t=3因此,在主函数中调用函数fun(a,&x)时,就是要将数组a中前4个元素逆置赋给数组x,最后输出x数组。

第6题:

下列程序的运行结果是()。includevoid fun(int*s,int*p){ static int t=3;*p=s[t];t--;

下列程序的运行结果是( )。#include<stdio.h>void fun(int*s,int*p){ static int t=3; *p=s[t]; t--;}void main(){ int a[]={2,3,4,5),k; int x; for(k=0;k<4;k++) { fun(a,&x); printf("%d,",x); }}

A.5,4,3,2

B.2,3,4,5,

C.2,2,2,2,

D.5,5,5,5,


正确答案:A
解析:分析fun函数程序段,可知fun函数要实现的功能是将s中第(t+1)个元素以前的元素逆置赋给数组p。由于fun中函数定义了静态变量t=3,因此,在主函数中调用函数fun(a,&x)时,就是要将数组a中前4个元素逆置赋给数组x,最后输出x数组。

第7题:

下列程序的运行结果是()。 include voidfun(int*s,int*p) {static int t=3; *p=s[t]; t

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

#include<stdio.h>

voidfun(int*s,int*p)

{ static int t=3;

*p=s[t];

t--;

}

void main()

{ int a[]={2,3,4,5},k;

int x;

for(k=0;k<4;k++)

{ fun(a,&x);

printf("%d,",x);

}

}

A.5,4,3,2

B.2,3,4,5,

C.2,2,2,2,

D.5,5,5,5,


正确答案:A
解析:分析fun函数程序段,可知fun函数要实现的功能是将s中第(t+1)个元素以前的元素逆置赋给数组p。由于fun中函数定义了静态变量t=3,因此,在主函数中调用函数fun(a,&x)时,就是要将数组a中前4个元素逆置赋给数组x,最后输出x数组。

第8题:

以下程序的输出结果是______。 fun(int *s,int *p) { static int t=3; *p=s[t]; t--; } main() { int str[]={1,2,3,4},i,m=0; for(i=0;i<4;i++) {fun(str,&m); printf("%d",m); } printf("\n"); }

A.0

B.444412

C.1234

D.4321


正确答案:D
解析:程序的功能是将字符数组str中的内容以反序输出。函数fun中t为静态变量,每一次调用函数fun时,t的值为上一次调用函数结束时的值。

第9题:

以下程序运行后,输出结果是______。 fun(int**s,int p[2][3]) {**s=p[1][1]; } main() { int a[2][3]={1,3,5,7,9,11},*p; p=(int *)malloc(sizeof(int)); fun(&p,a); printf("%d\n",*p); }

A.1

B.7

C.9

D.11


正确答案:C
解析:p是指向整型变量的指针,函数fun的第一个参数是指向指针变量的指针,调用时将p的地址传给了形参s,函数体**s=p[1][1]使得s的内容是p[1][1]的地址,即实参p里存放的是实参数组a[1][1]元素的地址,输出时取指针运算则输出元素a[1][1]=9。

第10题:

以下程序的输出结果是______。 fun(int **s,int p[2][3]) { **s=p[1][1]; } main() { int a[2][3]={1,3,5,7,9,11},*p; p=(int *)malloc(sizeof(int)); fun(&p,a); printf("%d\n",*p); }

A.1

B.7

C.9

D.11


正确答案:C