34 ) 有以下程序#include <stdio.h>int f(int n);main(){ int a=3,s;s=f(a);s=s+f(a);printf("%d\n",s);}int f(int n){ static int a=1;n+=a++;return n;}程序运行以后的输出结果是A)7B)8C)9D)10

题目

34 ) 有以下程序

#include <stdio.h>

int f(int n);

main()

{ int a=3,s;

s=f(a);s=s+f(a);printf("%d\n",s);

}

int f(int n)

{ static int a=1;

n+=a++;

return n;

}

程序运行以后的输出结果是

A)7

B)8

C)9

D)10


相似考题
更多“34 ) 有以下程序#include &lt;stdio.h&gt;int f(int n);main(){ int a=3,s;s=f(a);s=sf(a);prin ”相关问题
  • 第1题:

    以下程序的输出结果是includeint a[3][3]={1,2,3,4,5,6,7,8,9,},*p;main(){p=(int*)ma

    以下程序的输出结果是 #include<stdio.h> int a[3][3]={1,2,3,4,5,6,7,8,9,},*p; main() { p=(int*)malloc(sizeof(int)); f(p,a); printf("%d\n”,*p); free(p);} f(int *s,intp [][3]) { *s=p[1][1];}

    A.1

    B.4

    C.7

    D.5


    正确答案:D
    解析: 本题考查了二维数组元素引用的方法。题中用动态存储分配函数malloc分配了一个int型数据长度大小的内存,然后指针p指向了这段内存,函数f()中对p所指向的数据进行了赋值,p[1][1]为二维数组第二行第二列的元素,对应于实参a的元素5,所以输出结果为5。

  • 第2题:

    以下程序的输出结果是

    #include

    int a[3][3]={1,2,3,4,5,6,7,8,9,},*p;

    main( )

    { p=(int *)malloc(sized(int));

    f(p,a) ;

    printf("%d\n",*p);

    free(p);}

    f(int *s,int p[ ][3])

    { *s=p[1][1];}

    A.1

    B.4

    C.7

    D.5


    正确答案:D
    解析:本题考查了二维数组元素引用的方法。题中用动态存储分配函数malloc分配了一个int型数据长度大小的内存,然后指针p指向了这段内存,函数f( )中对p所指向的数据进行了赋值,p[1][1]为二维数组第二行第二列的元素,对应于实参a的元素5,所以输出结果为5。

  • 第3题:

    以下程序的输出结果是

    #include<stdio.h>

    int a[3][3]={1,2,3,4,5,6,7,8,9,},*p;

    main()

    { p=(int*)malloc(sizeof(int));

    f(p,a);

    printf("%d\n",*p);

    free(p); }

    f(int *s, int p[][3])

    { *s=p[1][1];}

    A.1

    B.4

    C.7

    D.5


    正确答案:D
    解析:本题考查了二维数组元素引用的方法。题中用动态存储分配函数malloc分配了一个int型数据长度大小的内存,然后指针p指向了这段内存,函数f()中对p所指向的数据进行了赋值,p[1][1]为二维数组第二行第二列的元素,对应于实参a的元素5,所以输出结果为5。

  • 第4题:

    以下程序的输出结果是()。includeint fun(int n,int *s){ int f1,f2;if(n==0||n==1)*s=

    以下程序的输出结果是( )。 #include<stdio.h> int fun(int n,int *s) { int f1,f2; if(n==0||n==1) *s=1; else { fun(n-1,&f1); fun(n-2,&f2); *s=f1+f2; } } void main() { int x; fun(6,&x); printf("\n%d" ,x);}

    A.7

    B.13

    C.9

    D.10


    正确答案:B
    解析:n=0或n=1是递归的终止条件。然后利用已知值逐步递推求出未知值。注意:通过传送地址值,在被调用函数中直接改变调用函数中的变量的值。

  • 第5题:

    有以下程序:includeiht fun(iht n,int*p){int f1,f2;if(n==1||,n==2)*p=1;else{fun(n-

    有以下程序: #include<stdio.h> iht fun(iht n,int*p) { int f1,f2; if(n==1||,n==2)*p=1; else { fun(n-1,&f1);fun(n-2,&f2); *p=f1+f2; } } main() { int s; fun(3,&s); printf("%d\n",s); } 程序的运行结果是______。

    A.2

    B.3

    C.4

    D.5


    正确答案:A
    解析: 本题考查的重点是理解递归函数。fun()为递归函数,递归结束条件时n为1或2,从而fun(3,&s)得fun(2,&s)+fun(1,&s)=1+1=2,因此选项A是正确的。

  • 第6题:

    有以下程序:includevoid fun(int* s,int* * d){* *d=*(s+2);}main(){ inta[]={1,2,3,

    有以下程序: #include <stdlib.h> void fun(int * s,int * * d) { * *d=*(s+2); } main() { int a[]={1,2,3,4,5},*b; b=(int *)malloc(sizeof(int)); fun(a,&B) ; printf("%d\n",*b+1); } 程序的输出结果是( )

    A.2

    B.3

    C.4

    D.5


    正确答案:C