Which two code fragments are most likely to cause a StackOverflowError?()
第1题:
有如下程序:
#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.
第2题:
设x和y均为int型变量,则执行下面的循环后,y值为( )。 public class Sun { public static void main(String args[ ]) { int x, y; for (y=1, x=1; y<=50; y++) { if(x>=10) break; if (x%2==1) { x+=5; continue; } x-=3; } System.out.println (y); } }
A.2
B.4
C.6
D.8
第3题:
阅读下面程序:
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);
}
则该程序的输出结果是______。
第4题:
下列程序的运行结果是( )。 #include<stdio.h> void sub(int*s,int*y) {static int m=4: *y=s[m]; m--; } void main() {int a[]={1,2,3,4,5},k,x; printf("\n"); for(k=0;k<=4;k++) {sub(a,&x); printf("%d,",x); } }
A.5,4,3,2,1,
B.1,2,3,4,5,
C.0,0,0,0,0,
D.4,4,4,4,4,
第5题:
for(int x=0,y=0;!x&&y<=5;y++)语句执行循环的次数是( )。
A.0
B.5
C.6
D.无穷
第6题:
下面程序段的输出结果为 package test; public class ClassA { int x=20; static int y=6; public static void main(String args[]) { ClassB b=new ClassB(); b.go(10); System.out.println("x="+b.x); } } class ClassB { int x; void go(int y) { ClassA a=new ClassA(); x=a.y; } }
A.x=10
B.x=20
C.x=6
D.编译不通过
第7题:
下列程序的运行结果是( )。 #include<stdio.h> void sub(int*s,int*y) {static int m=4; *y=s[0]; m++; } void main() {int a[]={1,2,3,4,5},k; int x; printf("\n"); for(k=0;k<=4;k++) {sub(a,&x); printf("%d,",x); } }
A.1,1,1,1,1,
B.1,2,3,4,5,
C.0,0,0,0,0,
D.4,4,4,4,4,
第8题:
阅读下面程序:
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),
}
则该程序的输出结果是【 】
第9题:
有如下类的定义。那么空格处的语句是( )。 class MyClass { ____________int x,y; public: MyClass(int x1=0,int y1=0) { x=x1; y=y1; } static void change() { x+=10; y+=10; } };
A.static
B.const
C.private
D.不需要填入内容
第10题:
下面程序段的输出结果为( )。 package test; public class ClassA { int x=20: static int y=6; public static void main(String args[]) { ClassB b=new ClassB; go(10); System.out.println("x="+b.x); } } class ClassB { int X; void go(int y) { ClassA a=new ClassA; x=a.Y ; } }
A.x=10
B.x=20
C.x=6
D.编译不通过