CMS专题

单选题55. int []x= {1, 2,3,4, 5};  56. int y[] =x;  57. System.out.println(y[2]);  Which is true?()ALine 57 will print the value 2.BLine 57 will print the value 3.CCompilation will fail because of an error in line 55.DCompilation will fail because of an erro

题目
单选题
55. int []x= {1, 2,3,4, 5};  56. int y[] =x;  57. System.out.println(y[2]);  Which is true?()
A

 Line 57 will print the value 2.

B

 Line 57 will print the value 3.

C

 Compilation will fail because of an error in line 55.

D

 Compilation will fail because of an error in line 56.

参考答案和解析
正确答案: B
解析: 暂无解析
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

若有以下程序: include using namespace std; int f(int x, int y) {return(y-x)*x;

若有以下程序:

include <iostream>

using namespace std;

int f(int x, int y)

{

return (y-x)*x;

}

int main()

{

int a=3,b=4,c=5,d;

d=f(f(a,b) ,f(a,c) );

cout<<d<<<end1;

return 0;

}

执行后的输出结果是【 】。


正确答案:9
9 解析:本题考核函数的嵌套调用。在主函数中执行语句“d=f(f(a,b) ,f(a,c));”调用了3次f()函数:调用f(a,b) 得到的值为3,调用f(a,c) 得到的值为6,调用f(3,6)得到的值为9。

第2题:

下列函数定义中,会出现编译错误的是 ______。

A.max(int x,int y,int *z) { *z=x>y? x:y;}

B.int max(int x,y) {int z; z=x>y? x;y; return z; }

C.max(int x,int y) { int z; z=x>y? x:y; return(z); }

D.int max(int x,int y) { return(x>y?x:y);}


正确答案:B
解析:本题考查函数的定义。选项B中函数形参y没有说明数据类型。

第3题:

阅读下面程序: include void fun(int n) { int x(5); static int y(10); if(n>0) {

阅读下面程序:

include<iostream.h>

void fun(int n)

{

int x(5);

static int y(10);

if(n>0)

{

++x;

++y;

cout<<x<<","<<y<<end1;

}

}

void main()

{

int m(1);

fun(m);

}

则该程序的输出结果是______。


正确答案:611
6,11

第4题:

有以下程序: include using namespace std; class Point' { public: void SetPoint(

有以下程序: #include <iostream> using namespace std; class Point' { public: void SetPoint(int x,int y); void Move(int xOff,int yOff); int GetX() { return X; } int GetY() { return Y; } private: int X,Y; }; void Point::SetPoint(int x, int y) { X=x; Y=y; } void Point: :Move(int xOff, int yOff) X+=xOff; Y+=yOff; } int main () { Point p1; p1.SetPoint(1,2); p1.Move (5, 6); cout<<"Point1 is ("<<p1.GetX()<<','<<p1.GetY()<<")"<<end1; return 0; } 执行后的输出结果是( )。

A.Point1 is (6,8)

B.Point1 is (1,2)

C.Point1 is (5,6)

D.Point1 is (4,4)


正确答案:A
解析:本题考核对象的定义与使用。程序中定义了一个类Point,在主函数中定义了一个Point类的对象p1,然后通过对象p1调用其成员函数SetPoint()和Move()实现移位的操作。

第5题:

有如下程序: include using namespace std; void f1(int& x, int& y){int z=

有如下程序:

#include<iostream>

using namespace std;

void f1(int& x, int& y){int z=x; x=y; y=z;)

void f2(int x, int y){int z=x; x=y; y=z;}

intmain(){

int x=10, y=26;

f1(x, y);

f2(x, y);

cout<<y<<end1;

return 0;

}

运行时的输出结果是( )。

A) 10

B) 16

C) 26

D) 36

A.

B.

C.

D.


正确答案:A

第6题:

以下程序执行后的输出结果是( )。include usingnamespacestd;void try(int,int,int,in

以下程序执行后的输出结果是( )。 #include <iostream> using namespace std; void try(int,int,int,int); int main ( ) { int x,y,z,r; x=1; y=2; try(x,y,z,r); cout<<r<<end1; return 0; } void try(int x,int y, int z,int r) { z = x+y; x = X*X; y = y*y; r = z+x+y; }

A.18

B.9

C.10

D.不确定


正确答案:D
解析:本题常见的错误解答是:把x=1,y=2代入到函数try中,逐步计算出r=8。最后得到r的输出值是8。下面是正确解答。根据程序逐步分析:①程序中定义了一个名为try的void型函数,即函数try()没有任何返回值。②而try()函数在主函数中是以一条独立语句的方式被调用的,且主函数最后输出变量r的值。③但在主函数中,并没有对变量r赋值。④在C++语言中,数据只能从实参单向传递给形参,称为按值传递。也就是说,当简单变量作为实参时,用户不能在函数中改变对应实参的值。所以,虽然在函数try()中,r的值为8,但它并不能传递给实参,当然最终的输出肯定是不确定的随机数了。

第7题:

下列函数定义中,会出现编译错误的是

A.max(int x,int y,int *z) { *z=x>y ? x:y; }

B.int max(int x,y) { int z; z=x>y ? x:y; return z; }

C.max(int x,int y) { int z; z=x>y?x:y; return(z); }

D.int max(int x,int y) { return(x>y?x:y); }


正确答案:B
解析:定义函数时,若需要声明形式参数时,则每个形式参数都必须单独声明类型。

第8题:

阅读下面程序: include void f(int n) { int x(5); static int y(10); if(n>0) { ++

阅读下面程序:

include<iostream.h>

void f(int n)

{

int x(5);

static int y(10);

if(n>0)

{

++x;

++y;

cout<<x<<","<<y<<endl;

}

}

void main()

{

int m(1);

f(m),

}

则该程序的输出结果是【 】


正确答案:611
6,11

第9题:

有如下程序: include using namespace std; class Point{ int x, y; public: Point(i

有如下程序:

#include<iostream>

using namespace std;

class Point{

int x, y;

public:

Point(int x1=0, int y1=0):x(x1), y(y1){}

int get(){return x+y;)

};

class Circle{

Point center;

int radius;

public:

Circle(int CX, int cy, int r):center(cx, cy), radius(r){}

int get(){return center. get()+radius;}

};

int main(){

circle c(3, 4, 5);

cout<<c. get()<<end1;

return ():

}

运行时的输出结果是( )。

A) 5

B) 7

C) 9

D) 12

A.

B.

C.

D.


正确答案:D

第10题:

下列程序的输出结果是______。 int t(int x,int y,int cp,int dp) { cp=x*X+y*y; dp=x*x-y*y; } main() { int a=4,b=3,c=5,d=6: t(a,b,c,d); printf("%d%d\n" ,c,d);

A.4 5

B.4 6

C.5 6

D.5 5


正确答案:C

更多相关问题