下列程序的运行结果是()。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);

题目
下列程序的运行结果是()。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,


相似考题
更多“下列程序的运行结果是()。#include<stdio.h>void fun (int*s,int*p){ static int t=3; *p=s [t]; ”相关问题
  • 第1题:

    下列程序的运行结果是()。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数组。

  • 第2题:

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

  • 第3题:

    以下程序的输出结果是( )。 include void swap(int*a,int*B){int*t; t=a;a=b;b=c;} main

    以下程序的输出结果是( )。 include<stdio.h> void swap(int*a,int*B){int*t; t=a;a=b;b=c;} main() {int i=3,j=5,*p=&i,*q=&j; swap(p,q);printf("%d %d\n",*p,*q); }


    正确答案:3 5
    3 5 解析:本题考查函数中形参和实参的传递。在C语言函数中实参和形参传递具有不可逆性,参数只能由实参传向形参,而不能由形参传向实参,虽然swap函数的功能是实现两个数的交换,但由于没有返回值,故最终的输出结果为3 5。

  • 第4题:

    下列程序的运行结果是()。 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数组。

  • 第5题:

    下列程序运行后,输出结果是______。 include include fun(char *w ,int

    下列程序运行后,输出结果是______。 #include <stdio. h> #include <string. h> fun (char *w ,int n) { char t,*s1,*s2; s1=w; s2=w+n-1; while (s1<s2) { t=*s1++; *s1=*s2--; *s2=t; } } main () { char *p; p="1234567"; fun (p, strlen (p)); puts (p); }

    A.1234567

    B.7654321

    C.1711717

    D.7177171


    正确答案:C