以下程序执行的结果是什么?()  int[] myArray = new int[3];  try{  for(int i=0; i<=myArray.length;i++){  myArray[i]=i*3;   System.out.println("myArray数组的第"+i+"个元素的值是:"+myArray[i]);       }  }catch(ArrayIndexOurOfBoubsException e){  System.out.println("数组下标越界");} A、程序执行

题目

以下程序执行的结果是什么?()  int[] myArray = new int[3];  try{  for(int i=0; i<=myArray.length;i++){  myArray[i]=i*3;   System.out.println("myArray数组的第"+i+"个元素的值是:"+myArray[i]);       }  }catch(ArrayIndexOurOfBoubsException e){  System.out.println("数组下标越界");} 

  • A、程序执行,屏幕上显示“数组下标越界”
  • B、程序出现异常,屏幕上提示出现数组下标越界异常
  • C、程序正常执行结束,屏幕上显示数组中每个元素的值
  • D、程序编译出错

相似考题
更多“以下程序执行的结果是什么?()  int[]&ens”相关问题
  • 第1题:

    以下程序执行后的输出结果是( )。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,但它并不能传递给实参,当然最终的输出肯定是不确定的随机数了。

  • 第2题:

    执行以下程序的输出结果是( )。 includedefine M 5define N M+M main(){int k; k=N*N*5;

    执行以下程序的输出结果是( )。

    include<stdio.h>

    define M 5

    define N M+M

    main()

    { int k;

    k=N*N*5;printf(”%d\n" ,k);

    }


    正确答案:55
    55 解析:本题考查的重点是对宏定义的理解。#define指令定义一个标识符和一个串,编译程序在对C源程序处理时.发现该标识符都用该串替换,因此,在语句k=N*N*5将替换成k=M+M*M+M*5后,M被替换成5,从而k=5+5*5+5*5=55。

  • 第3题:

    以下程序的执行结果是【】。includeincludeclass Sample{ public: int x,y;

    以下程序的执行结果是【 】。

    include<iostream.h>

    include<stdlib.h>

    class Sample

    {

    public:

    int x,y;

    Sample(){x=y=0;}

    Sample(int a,int b) {x=a;y=b; }

    void disp()

    {

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

    }

    };

    void main() {

    Sample s1(2,3);

    s1.disp();

    }


    正确答案:x=2y=3
    x=2,y=3

  • 第4题:

    以下程序的执行结果是 ( )。include using namespace std;class sample{private: int

    以下程序的执行结果是 ( )。 #include <iostream> using namespace std; class sample { private: int x; public: sample (int A) { x=a; } friend double square(sample s); }; double square(sample s) {

    A.20

    B.30

    C.900

    D.400


    正确答案:C
    解析:本题考核友元函数的应用。程序中函数square()是类sample的一个友元函数,它可以直接访问类sample的所有成员。它的功能是返回类sample的私有数据成员x的平方。所以程序的执行结果是:900。注意:友元函数不是类的成员函数,在类外定义时不要加上类名及其作用域运算符(::)。友元函数的调用与一般函数的调用的方式和原理一致,可以在程序的任何地方调用它。

  • 第5题:

    以下程序的执行结果是【 】。 include class Sample { public: int x: int y; void di

    以下程序的执行结果是【 】。

    include<iostream. h>

    class Sample

    {

    public:

    int x:

    int y;

    void disp()

    {

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

    }

    };

    void main()

    {

    int Sample:: ** pc;

    Sample s;

    pc=& Sample: :x;

    s.*pc=10;

    pc:=&Sample: :y;

    s.*pc=20;

    s.disp();

    }


    正确答案:x=10y=20
    x=10,y=20 解析:本题比较特殊,考察域作用符的使用规则。其实际含义是;指针先指向x,然后指向y,并利用该指针分别为x和y赋值。在使用过程中进行了作用域的限定。

  • 第6题:

    给出以下程序的执行结果【】。 include using namespace std; int n=1; void Fun(); int

    给出以下程序的执行结果【 】。

    include <iostream>

    using namespace std;

    int n=1;

    void Fun();

    int main ()

    {

    n++;

    Fun ( );

    if (n>0)

    {

    int n=5;

    cout<<"Block: n="<<n<< ", ";

    }

    cout<< "Main: n="<<end1;

    return 0;

    }

    void Fun ( )

    {

    int n=10;

    cout<<"Fun: n="<<n<<",";

    }


    正确答案:Fun:n=10Block:n=5Main:n=2
    Fun:n=10,Block:n=5,Main:n=2 解析:变量的作用域是程序中变量有效的区域,它是变量的一个重要特征。在题中,变量n有3种身份,其一是作为全局变量的n,其二是作为if语句块内局部变量的n,其三是函数内部局部变量的n。程序最后要求输出各个作用域内n的值。

  • 第7题:

    以下程序的执行结果为()。includeClass sample{ int n;public: sample(int i){n=i;}

    以下程序的执行结果为( )。 #include<iostream.h> Class sample { int n; public: sample(int i){n=i; } operator ++() { n++; } void display() {cout<<n<<end1; } }; void main() { sample obj(5); obj++;

    A.5

    B.6

    C.7

    D.8


    正确答案:B
    解析:本题考核运算重载的简单应用。程序中通过“++”运算符重载将obj++转换成对类的私有变量n的增1运算。所以程序最后输出为6。

  • 第8题:

    以下程序的执行结果是 ______。 include int &max(int &x,int &y) { ret

    以下程序的执行结果是 ______。

    include<iostream.h>

    int &max(int &x,int &y)

    {

    return(x>y? x:y);

    }

    void main()

    {

    int n=2,m=10;

    max(n,m)--;

    cout<<"n="<<n<<",m="<<m<<endl;

    }


    正确答案:n=2m=9
    n=2,m=9

  • 第9题:

    分析以下程序的执行结果【】。include class S{ int A[10]; public: int &operato

    分析以下程序的执行结果【 】。

    include <iostream. h>

    class S{

    int A[10];

    public:

    int &operator () (int);

    };

    int &S: :operator() (int x) {

    return A[x];

    }

    void main() {

    S a;

    int i,j;

    for (i=0; i<10; i++)

    a(i)=i*2;

    for (i=0; i<10; i++)

    cout<<a(i)<<" ";

    cout<<end1; }


    正确答案:0 2 4 6 8 10 12 14 16 18
    0 2 4 6 8 10 12 14 16 18

  • 第10题:

    以下程序执行后的输出结果是include using namespace std;void try(int,int,int,int)

    以下程序执行后的输出结果是 #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<<endl; 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函数在main函数中是以一条独立语句的方式被调用的,且main函数最后输出变量r的值。但在main函数中,并没有对变量r赋值。在c++语言中,数据只能从实参单向传递给形参,称为按值传递。也就是说,当简单变量作为实参时,用户不能在函数中改变对应实参的值。所以虽然在函数try中,r的值为8,但它并不能传递给实参,当然最终的输出肯定是不确定的随机数了。

  • 第11题:

    有以下程序:include using namespace std;int main(){ int intone; int &rInt=in

    有以下程序: #include <iostream> using namespace std; int main() { int intone; int &rInt=intone; intone=5; rInt=7; cout<<intOne<<","<<rInt<<end1; return 0; } 上述程序执行后的输出结果是( )。

    A.5,7

    B.7,5

    C.5,5

    D.7,7


    正确答案:D
    解析:程序中,引用rim用intone初始化以后,无论改变intOne还是rInt,实际上都是intone,两者的值是一样的。所以执行语句“rInt=7;”后,整型变量intOne、rInt的值都被置为7。

  • 第12题:

    执行以下程序时输入1234567,则输出结果是【 】。 includemain(){int a=1,b; scanf("%2

    执行以下程序时输入1234567<CR>,则输出结果是【 】。

    include <stdio.h>

    main()

    { int a=1,b;

    scanf("%2d%2d",&a,&b); prinff("%d %dhn",a,b);

    }


    正确答案:12  34
    12  34 解析:本题考查的知识点是:Scanf()函数。 scanf()是标准输入函数;其第1个参数为格式控制字符串。其中“%2d”表示读入一个2个字符宽的整数。所以本题代码将连续读入2个2字符宽的整数分别存到变量a和b中。根据题目要求,输入数据1234567CR>,则scanf()读入的两个整数分别为 12和34,故输出结果为12  34。

  • 第13题:

    以下程序的执行结果是【】。 include include void pnnt(int n) { if (n!=0

    以下程序的执行结果是【 】。

    include<iostream.h>

    include<iomanip.h>

    void pnnt(int n)

    {

    if (n!=0)

    {

    Print(n-1);

    for (int i=1;i<=n;i++)

    cout<<setw(3)<<i;

    cout<<endl;

    }

    }

    void main()

    {

    print(4);

    }


    正确答案:1 12 123 1234
    1 12 123 1234

  • 第14题:

    以下程序的执行结果是______。 inelude class Sample { public: int x; int y; void

    以下程序的执行结果是______。

    inelude<iostream.h>

    class Sample

    {

    public:

    int x;

    int y;

    void disp( )

    {

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

    }

    };

    void main( )

    {

    int Sample::*pc;

    Sample s;

    pc=&Sample::x;

    s.*pc=10;

    pc=&Sample::y;

    s.*pc=20;

    s.disp( );

    }


    正确答案:x=10y=20
    x=10,y=20 解析:本题比较特殊,考察域作用符的使用规则。其实际含义是:指针先指向x,然后指向y,并利用该指针分别为x和y赋值。在使用过程中进行了作用域的限定。

  • 第15题:

    分析以下程序执行结果【】。 include int f (int x, int y){return x,y; } double f (d

    分析以下程序执行结果【 】。

    include<iostream.h>

    int f (int x, int y){

    return x,y;

    }

    double f (double x, double y) {

    return x,y;

    }

    void main() {

    int a=4, b=6;

    double c=2.6, d=7.4;

    cout<<f (a, b) <<","<<f (c, d) <<end1;

    }


    正确答案:24 19.24
    24, 19.24

  • 第16题:

    有以下程序:includeint a=2;int f(int *a){return (*a) ++;}main(){ int s=0;{ int a=

    有以下程序: #include <stdio.h> int a=2; int f(int *a) { return (*a) ++;} main() { int s=0; { int a=5; s+=f(&a); } s+=f(&a); printf("%d\n",s) } 执行后的输出结果是( )。

    A.10

    B.9

    C.7

    D.8


    正确答案:C
    解析:在一个函数内部定义的变量是内部变量,它只在本函数范围内有效,也就是说只有在本函数内才能使用这些变量。对于main函数中的{inta=5;s+=f(&a);},a只在花括号内有效。在函数之外定义的变量称为外部变量,外部变量是全局变量,它的有效范围是从定义该变量的位置开始到本源文件结束。程序开头的定义inta=2;使a成为全局变量,main函数中第二个s+=f(&a);语句中的a就是这个全局变量。

  • 第17题:

    执行以下程序后的输出结果为 ( )。includeUsing namespace std;void fun(int x, int y

    执行以下程序后的输出结果为 ( )。#include<iostream>Using namespace std;void fun(int x, int y, int *cp, int *dp) {*cp=x+ y; 2*dp=x- y;}void maia() {int a, b, c, d; a=30; b=50; fun(a, b, &c, &d); cout<<c<<','<,d<<end1;}

    A.50, 30

    B.30, 50

    C.80, 20

    D.80, 20


    正确答案:C

  • 第18题:

    以下程序的执行结果是______。 include class CSample{ private: int n; static int

    以下程序的执行结果是______。

    include<iostream.h>

    class CSample

    {

    private:

    int n;

    static int k:

    public:

    CSample (int i) {n=i;k++;};

    voiddisp();

    } ;

    void CSample::disp()

    {

    cout <<"n="<<n<<",k="<<k<<endl

    }

    int CSample:


    正确答案:n=10k=3 n-20k=3 n=30k=3
    n=10,k=3 n-20,k=3 n=30,k=3

  • 第19题:

    以下程序的执行结果为【】。 include using namespace std; void overload(int num) {cou

    以下程序的执行结果为【 】。

    include<iostream>

    using namespace std;

    void overload(int num)

    {

    cout<<num<<end1;

    }

    void overload(char ch)

    {

    char c=ch+1;

    cout<<c<<end1;

    }

    int main()

    {

    overload('X');

    return 0;

    }


    正确答案:Y
    Y 解析:本题考核函数重载。在本题中,函数overload()有两次实现。第一次实现中,其形参为int型;第2饮实现中,其形参为char型,所以构成了函数重载。主函数中调用overload()函数时传递的实参为字符'X',所以执行函数的第2次实现。输出Y。

  • 第20题:

    以下程序执行后输出的结果是【】。 include using namespace std; int fac(int a,int b){

    以下程序执行后输出的结果是【 】。

    include<iostream>

    using namespace std;

    int fac(int a,int b){

    return(b-a)*a;

    }

    int main(){

    int x=3,y=4,z=5,result;

    result=fac(fac(x,y),fac(x,z));

    cout<<result<<endl;

    return 0;

    }


    正确答案:9
    9 解析:在main()函数中执行result=fac(fac(x,y),fac(x,2));调用了三次fac()函数: fac(x,y)的值为3,fac(x,z)的值为6,fac(3,6)得到的值为9。

  • 第21题:

    若有以下程序:includeusing namespace std;int main(){ int a=3; cout<<(a+=a-=a+A)

    若有以下程序: #include <iostream> using namespace std; int main() { int a=3; cout<<(a+=a-=a+A) <<end1; return 0; } 程序执行后的输出结果是( )。

    A.-6

    B.12

    C.0

    D.-12


    正确答案:D
    解析:本题考核运算符的优先级和结合性。根据运算符的优先级和结合性用括号来分出表达式的优先级:a+=(a-=(a*A))。先计算a*a得9,再执行语句:a-=9:得到a=-6,然后执行a+=a得到结果-12。

  • 第22题:

    以下程序的执行结果是()。includeint fun(int b[],int n){int i,r=1;for(i=0;i

    以下程序的执行结果是( )。 #include<iostream.h> int fun(int b[],int n) { int i,r=1; for(i=0;i<n;i++) r=r*b[i]; } void main() { int x,a[]={1,2,3,4,5,6,7,8}; x=fun(a,3); cout<<x<<endl; }

    A.5

    B.6

    C.7

    D.8


    正确答案:B

  • 第23题:

    以下程序执行后的输出结果是include.using namespace std;void try(int,int,int,int)

    以下程序执行后的输出结果是 #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函数在main函数中是以一条独立语句的方式被调用的,且main函数最后输出变量r的值。但在main函数中,并没有对变量r赋值。在C++语言中,数据只能从实参单向传递给形参,称为按值传递。也就是说,当简单变量作为实参时,用户不能在函数中改变对应实参的值。所以虽然在函数try中,r的值为8,但它并不能传递给实参,当然最终的输出肯定是不确定的随机数了。