单选题下列重载函数中,正确的是(  )。A void fun(int a,float b);void fun(int C,float d)B void fun(int a,float b);void fun(float a,int b)C float fun(int a,float b);int fun(int b,float a)D int fun(int a,int b);float fun(int a,int b)

题目
单选题
下列重载函数中,正确的是(  )。
A

void fun(int a,float b);void fun(int C,float d)

B

void fun(int a,float b);void fun(float a,int b)

C

float fun(int a,float b);int fun(int b,float a)

D

int fun(int a,int b);float fun(int a,int b)


相似考题
参考答案和解析
正确答案: D
解析:
函数重载是指同一函数名可以对应多个函数实现。进行函数重载时,要求同名函数在参数个数上不同,或者参数类型上不同,只有返回类型不同的函数不能重载。
更多“单选题下列重载函数中,正确的是(  )。A void fun(int a,float b);void fun(int C,float d)B void fun(int a,float b);void fun(float a,int b)C float fun(int a,float b);int fun(int b,float a)D int fun(int a,int b);float fun(int a,int b)”相关问题
  • 第1题:

    若已经声明了函数原型“void fun(int a,double b=0.0);”,则下列重载函数声明中正确的是( )。

    A.void fun(int a=90,double b=0.0);

    B.int fun(int a,double B);

    C.void fun(double a,int B);

    D.bool fun(int a,double b=0.0);


    正确答案:C
    解析:此题考查的是函数重载。在C++语言中,允许定义一系列函数名相同,但形参的个数和类型不完全相同的函数,即函数的重载。重载函数对返回值类型不做要求,返回值类型也不参与区分函数的重载形式。选项A)中参数表相同,返回类型也相同,所以错误。选项B),选项D)中相同参数表,不同返回类型所以错误。

  • 第2题:

    若各选项中所用变量已正确定义,fun()函数中通过return语句返回一个函数值,下列选项中错误的程序是( )。

    A.main() {……x=fun(2,10);……} float fun(int a,int b){……}

    B.float fun(int a,int b){……} main() {……x=fun(i,j);……}

    C.float fun(int,int); main() {……x=fun(2,10);……} float fun(int a,int b){……}

    D.main() {float fun(int I,intj); ……x=fun(i,j);……} float fun(int a,int b){……}


    正确答案:A
    解析:C语言规定,函数必须先定义,后调用(函数的返回值类型为int或char时除外)。在选项A)中,调用的子函数在调用后面定义,所以不正确。在选项B)、C)中,被调用函数在主调函数之前定义,再在主函数中调用,所以是正确的;在选项D)中,在主调函数中先对子函数float fun(int i,int j)进行了定义,然后进行调用。

  • 第3题:

    有以下程序includefloat fun(int x,int y){return(x+y);}void main( ){int a=2,b=5

    有以下程序 #include<iostream.h> float fun(int x,int y) {return(x+y);} void main( ) {int a=2,b=5,c=8; cout<<fun((int)fun(a+c,b) ,a-c) ;}程序运行后的输出结果是

    A.编译出错

    B.9

    C.21

    D.9


    正确答案:B
    解析:本题的运算过程是fun((int)fun (a+c,B,a-C,fun((int)fun(10,5),2-8),fun ((int)15.000000,-6),fun(15,-6)=9。

  • 第4题:

    以下( )成员函数表示纯虚函数。

    A.virtual int fun(int)

    B.void fun(int)=0

    C.virtual void fun()=0

    D.virtual void fun(int){}


    正确答案:C
    解析:纯虚函数是在声明虚函数时被“初始化”为。的函数。定义的一般形式为:virtual函数类型函数名(参数列表)=0。所以排除选项A)、B)、D)。

  • 第5题:

    已知函数fun的原型为

    int fun(int,int,int);

    下列重载函数原型中错误的是

    A.char fun(int,int);

    B.double fun(int,int,double);

    C.int fun(int,char木);

    D.float fun(int,int,int);


    正确答案:D
    解析:重载函数至少要在参数个数或参数类型上有所不同。选项D)的重载函数只有返回值不同,其他(参数个数及类型)完全相同。因此,本题答案为D)。

  • 第6题:

    有以下程序includevoid fun(float* p1,int n1,float,*p2,int n2,float* s){ int i;s=(

    有以下程序 #include<stdio.h> void fun(float * p1,int n1,float,*p2,int n2,float * s) { int i; s=(float *)calloc(1,sizeof(float)); *s=0; for(i=0;i<n1;i++) *s+=*p1++; for(i=0;i<n2;i++) *s+=*p2++; } main() { float a[2]={1.1,2.2},b[3]={10.0,20.0,30.0),*s=a; fun(a,2,b,3,s); printf("%f\n",*s); } 上面程序的输出结果是( )

    A.60

    B.3.3

    C.63.3

    D.1.1


    正确答案:D

  • 第7题:

    若各选项中所有变量已正确定义,函数fun中通过return语句返回一个函数值,以下选项中错误的程序是______。

    A.mam() {…… x=fun(2,10); ……} fioat fun(int a,int b) { ……}

    B.float fun (int a,int b) {……} main() {…… x=fun(i,j); ……}

    C.float fun (int int); main() {…… x=fun(2,10); ……} float fun (int a,int b){ ……}

    D.main() { float fun (int i, int j); …… x=fun(i,j); ……} float fun (int a,int b){ ……}


    正确答案:A
    解析:C语言程序是由—个主函数和若干个其他函数组成的,主函数的函数名为:main(),main()函数在程序中的位置是任意的。C语言程序是从main()函数开始执行,当程序中定义了多个函数时,通常情况下是先定义后调用,若被调函数定义在主调函数之后,则必须先声明后调用。在选项A中,先执行main()函数,此时对fun()函数进行调用,由于fun函数在此调用之前无定义也无声明,故无法正常识别调用,所以选项A的程序错误。

  • 第8题:

    下列重载函数中,正确的是( )。

    A.void fun(int a,float b);void fun(int C,float d)

    B.void fun(int a,float b);void fun(float a,int b)

    C.float fun(int a,float b);int fun(int b,float a)

    D.int fun(int a,int b);float fun(int a,int b)


    正确答案:B

  • 第9题:

    若下列各选项中所有变量已正确定义,函数fun通过return语句返回一个函数值,以下选项中错误的程序是( )。

    A.main( ) {...... x = fun(2,10);......} float fun(int a, int b){......}

    B.float fun( int a,int b){......} main( ) {......x = fun(i,j);......}

    C.float fun(int, int); main( ) {......x=fun(2,10);......} float fun(iht a, int b){......}

    D.main( ) { float fun(int i, int j); ...... x = fun(i,j);......} float fun(int a,int b) {......}


    正确答案:A
    解析:C语言程序从main函数开始执行,当程序中定义了多个函数时,通常情况下是先定义后调用。若被调用函数定义在主调函数之后,则必须先声明后调用。在选项A)中,先执行main函数,并调用了fun函数,而fun函数在此调用之前无定义也无声明,故无法正常识别调用,所以错误。

  • 第10题:

    下面的方法重载,正确的是()。

    • A、int fun(int a, float b) { }  float fun(int a, float b) { }
    • B、float fun(int a, float b) { } float fun(int x, float y) { }
    • C、float fun(float a) { }  float fun(float a, float b) { }
    • D、float fun1(int a, float b) { }  float fun2(int a, float b) { }

    正确答案:C

  • 第11题:

    public class MethodOver  {  public void setVar (int a, int b, float c)  {  }  }   Which two overload the setVar method?()  

    • A、 Private void setVar (int a, float c, int b)  { }
    • B、 Protected void setVar (int a, int b, float c) { }
    • C、 Public int setVar (int a, float c, int b) (return a;)
    • D、 Public int setVar (int a, int b, float c) (return a;)
    • E、 Protected float setVar (int a, int b, float c) (return c;)

    正确答案:A,C

  • 第12题:

    单选题
    下面的方法重载,正确的是()。
    A

    int fun(int a, float b) { }  float fun(int a, float b) { }

    B

    float fun(int a, float b) { } float fun(int x, float y) { }

    C

    float fun(float a) { }  float fun(float a, float b) { }

    D

    float fun1(int a, float b) { }  float fun2(int a, float b) { }


    正确答案: A
    解析: 暂无解析

  • 第13题:

    ( 21 )已知函数 fun 的原型为

    int fun ( int,int,int ) ;

    下列重载函数原型中错误的是

    A ) char fun ( int,int ) ;

    B ) double fun ( int,int,double ) ;

    C ) int fun ( int,char* ) ;

    D ) float fun ( int, int, int ) ;


    正确答案:D

  • 第14题:

    若有以下调用语句,则不正确的fun函数的首部是

    main()

    { …

    int a[50],n;

    fun(n, &a[9]);

    }

    A.void fun(int m, int x[])

    B.void fun(int s, int h[41])

    C.void fun(int p, int *s)

    D.void fun(int n, int a)


    正确答案:D

  • 第15题:

    有以下程序:includeFloat fun(int x, int y){return(x+y) ;}void main( ){int a=2,

    有以下程序: #include<iostream.h> Float fun(int x, int y) { return(x+y) ;} void main( ) { int a=2,b=5,c=8; cout < < fun((int) fun(a+c, b) ,a-c) ;} 程序运行后的输出结果是

    A.编译出错

    B.9

    C.21

    D.9.0


    正确答案:B
    解析:本题的运算过程是fun((int) fun (a+c, b) ,a-c) ,fun((int) fun(10,5) ,2-8) ,fun ((int) 15.000000,-6) ,fun(15,-6) =9。

  • 第16题:

    若有以下调用语句,则不正确的fun函数的首部是( )。 main() { … int a[50],n; … fun(n,&a[9]); … }

    A.void fun(int m,int x[])

    B.void fun(int s,int h[41])

    C.voidfun(int p,int*s)

    D.void fun(int n,iht a)


    正确答案:C
    解析:根据主函树中的函数调用可知,第一个实参为整型数据,第二个实参为整型数组中一个元素的地址值。因此函数fun()的第二个形参应该为一个指针,故应该选择C。实参不是将整个数组传递给形参,故选项A和B不正确;选项D的第二个形参的数据类型与实参的数据类型不符。

  • 第17题:

    有下列函数定义: fun(float h) { printf("%f,%f\n",h,h*h);) 该函数的类型是( )。A.int类型SX

    有下列函数定义: fun(float h) { printf("%f,%f\n",h,h*h);) 该函数的类型是( )。

    A.int类型

    B.float类型

    C.void类型

    D.函数无类型说明,定义有错


    正确答案:A
    本题考查函数值的类型,在函数定义时,由于函数没有说明其类型,系统默认一律自动按整型(int)处理。

  • 第18题:

    有以下程序 #include<iostream.h float fun(int x,int y) {return(x+y);} void main() {int a=2,b=5,c=8; cout<<fun((int)fun(a+c,b),a-c);} 程序运行后的输出结果是( )。

    A.编译出错

    B.9

    C.21

    D.9


    正确答案:B

  • 第19题:

    若已经声明了函数原型“void fun(int a,double b=0.0);”,则下列重载函数声明中正确的是

    A.void fun(int a=90,double b=0.0);

    B.int fun(int a,double B) ;

    C.void fun(double a,intB) ;

    D.bool fun(int a,double b=0.0);


    正确答案:C

  • 第20题:

    若有以下调用语句,则不正确的 fun 函数的首部是( )。 void main() { int a[50],n; fun(n,&a[9]); }

    A.void fun(int m,int x[])

    B.void fun(int s,int h[])

    C.void fun(intp,int * s)

    D.void fun(int n,int a)


    正确答案:D
    解析:&a[9]表示对变量a[9]的引用,与它对应的形参必须是表示地址的变量,而D的第2个形参是一个普通变量。

  • 第21题:

    以下正确的函数原型为()

    • A、fun1(int x;int y);
    • B、void fun1(x,y);
    • C、void fun1(int x,y);
    • D、void fun1(int,int);

    正确答案:D

  • 第22题:

    public class MethodOver {   private int x, y;   private float z;   public void setVar(int a, int b, float c){   x = a;   y = b;   z = c;   }   }   Which two overload the setVar method?()

    • A、 void setVar (int a, int b, float c){  x = a;  y = b;  z = c;  }
    • B、 public void setVar(int a, float c, int b) {  setVar(a, b, c);  }
    • C、 public void setVar(int a, float c, int b) {  this(a, b, c);  }
    • D、 public void setVar(int a, float b){  x = a;  z = b;  }
    • E、 public void setVar(int ax, int by, float cz) {  x = ax;  y = by;  z = cz;  }

    正确答案:B,D

  • 第23题:

    多选题
    public class MethodOver  {  public void setVar (int a, int b, float c)  {  }  }   Which two overload the setVar method?()
    A

    Private void setVar (int a, float c, int b)  { }

    B

    Protected void setVar (int a, int b, float c) { }

    C

    Public int setVar (int a, float c, int b) (return a;)

    D

    Public int setVar (int a, int b, float c) (return a;)

    E

    Protected float setVar (int a, int b, float c) (return c;)


    正确答案: D,C
    解析: 暂无解析