NullpointerException
ArithmeticExceptioin
ArrayIndexOutOfBoundsException
SecurityManager
第1题:
对高级语言源程序进行编译时,可发现源程序中的(21)错误。
A.堆栈溢出
B.变量未定义
C.指针异常
D.数组元素下标越界
第2题:
阅读以下程序说明和C++程序,将程序段中(1)~(5)空缺处的语句填写完整。
[说明]
C++语言本身不提供对数组下标越界的判断。为了解决这一问题,在以下[C++程序]中定义了相应的类模板,使得对于任意类型的二维数组,可以在访问数组元素的同时,对行下标和列下标进行越界判断,并给出相应的提示信息。
[C++程序]
include <iostream.h>
template <class T> class Array;
template <Class T> class ArrayBody {
friend (1);
T* tpBody;
int iRows,iColumns, iCurrentRow;
ArrayBody(int IRsz, int iCsz) {
tpBody =(2);
iRows = iRsz;
iColumns = iCsz;
iCurrentRow = -1;
}
Public:
T& operator[] (int j) {
bool row_error, column_error;
row_error = column_error =false;
try {
if (iCurrentRow < 0 || iCurrentRow >= iRows)
row_error = true;
if (j<0 || j>= iColumns)
column_error = true;
if (row_error == true || column_error == true)
(3);
}
catch(char){
if (row_error == true)
cerr << "行下标越界[" << iCurrentRow << "]";
if (column_error = true)
cerr << "列下标越界[" << j << "]";
cout << "\n";
}
return tpBody[iCurrentRow * iColumns + j];
}
~Arraygody(){delete[]tpBody;}
};
template <class T> class Array {
ArrayBody<T> tBody;
Public;
ArrayBody<T> & operator[] (int i) {
(4);
return tBody;
}
Array(int iRsz, int iCsz) :(5) { }
};
void main()
{
Array<int> a1(10,20);
Array<double> a2(3,5);
int b1;
double b2;
b1 = a1[-5][10]; //有越界提示:行下标越界[-5]
b1 = a1[10][15]; //有越界提示:行下标越界[10]
b1 = a1[1][4]; //没有越界提示
b2 = a2[2][6]; //有越界提示:列下标越界[6]
b2 = a2[10][20]; //有越界提示:行下标越界[10]列下标越界[20]
b2 = a2[1][4]; //没有越界提示
}
第3题:
以下程序执行的结果是什么?()int[]myArray=newint[3];try{for(inti=0;i<=myArray.length;i++){myArray[i]=i*3;System.out.println("myArray数组的第"+i+"个元素的值是:"+myArray[i]);}}catch(ArrayIndexOurOfBoubsExceptione){System.out.println("数组下标越界");}
A.程序执行,屏幕上显示“数组下标越界”
B.程序出现异常,屏幕上提示出现数组下标越界异常
C.程序正常执行结束,屏幕上显示数组中每个元素的值
D.程序编译出错
第4题:
编译程序在语法分析阶段能检查出______错误。
A.表达式中的括号不匹配
B.以零作除数
C.数组下标越界
D.无穷递归
第5题:
已知一维数组类ARRAY的定义如下,ARRAY与普通一维数组区别是:其重载的运 算符[]要对下标是否越界进行检查。
ARRAY∷;v[n](或*(v+n))
略
第6题:
数组下标越界时产生的异常是()类型的异常。
第7题:
在Java语言中,在程序运行时会自动检查数组的下标是否越界,如果越界,会抛掷下面的()异常。
第8题:
下列说法正确的是()
第9题:
在C#中,编译时对数组下标越界将作检查
在C#中,程序运行时,数组下标越界也不会产生异常
在C#中,程序运行时,数组下标越界是否产生异常由用户确定
在C#中,程序运行时,数组下标越界一定会产生异常
第10题:
NullpointerException
ArithmeticExceptioin
ArrayIndexOutOfBoundsException
SecurityManager
第11题:
程序执行,屏幕上显示“数组下标越界”
程序出现异常,屏幕上提示出现数组下标越界异常
程序正常执行结束,屏幕上显示数组中每个元素的值
程序编译出错
第12题:
第13题:
试题(21)
对高级语言源程序进行编译时,可发现源程序中的 (21) 错误。
(21)
A. 堆栈溢出
B. 变量未定义
C. 指针异常
D. 数组元素下标越界
试题(21)分析
本题考查编译过程基本知识。
高级语言源程序中的错误分为两类:语法错误和语义错误,其中语义错误又可分为静态语义错误和动态语义错误。语法错误指语言结构上的错误,静态语义错误指编译时就能发现的程序含义上的错误,动态语义错误只有在程序运行时才能表现出来。堆栈溢出、指针异常和数组元素下标越界都是程序运行中才能出现的问题,而遵循先声明后引用原则的程序语言必须先定义变量,然后才能使用,否则编译器会在语法分析阶段指出变量未定义错误。
参考答案
(21)B
第14题:
阅读下列C++程序和程序说明,将应填入(n)处的字句写在对应栏内。
【说明】
C++语言本身不提供对数组下标越界的判断。为了解决这一问题,在程序6中定义了相应的类模板,使得对厂任意类型的二维数组,可以在访问数组元素的同时,对行下标和列下标进行越界判断,并给出相应的提示信息。
include<iostream.h>
template <class T> class Array;
template <class T> class ArrayBody {
friend (1)
T* tpBody;
int iRows, iColumns, iCurrentRow;
ArrayBody (int iRsz, int iCsz) {
tpBody =(2)
iRows = iRsz; iColumns =iCsz; iCurrentRow =-1;
}
public:
T& operator[] (int j) {
bool row_error, column_error;
row_error=column_error=false;
try{
if (iCurrentRow < 0 || iCurrentRow >=iRows)
row_error=true;
if (j < 0 || j >=iColumns)
column_error=true;
if ( row_error==true || column_error == true)
(3)
}
catch (char) {
if (row_error==true)
cerr << "行下标越界[" << iCurrentRow << "] ";
if (column_error== true )
cerr << "列下标越界[" <<j << "]";
cout << "\n";
}
return tpBody[iCurrentRow * iColumns +j];
};
~ArrayBody ( ) { delete[] tpBody; }
};
template <class T> class Array {
ArrayBody<T> tBody;
public:
ArrayBody<T> & operator[] (int i) {
(4)
return tBody;
}
Array (int iRsz, int iCsz) :(5) {}
};
void main()
{ Array<int>a1(10,20);
Array<double>a2(3,5);
int b1;
double b2;
b1=a1[-5][10]; //有越界提示:行下标越界[-5]
b1=a1[10][15]; //有越界提示:行下标越界[10]
b1=a1[1][4]; //没有越界提示
b2=a2[2][6]; //有越界提示:列下标越界[6]
b2=s2[10][20]; //有越界提示:行下标越界[10]列下标越界[20]
b2=a2[1][4]; //没有越界提示
}
第15题:
阅读下列说明和C++程序,将应填入(n)处的字句写在对应栏内。
【程序1说明】
程序1中定义了数组的类模板,该模板使得对于任意类型的二维数组,可以在访问数组元素的同时,对行下标和列下标进行越界判断,并给出相应的提示信息(C++语言本身不提供对下标越界的判断)。
【程序1】
include < iostream. h >
template < class T > class Array2D;
template < class T > class Array2DBody {
friend (1);
T * tempBody;
int iRows, iColumns, iCurrentRow;
Array2DBody(int Rows,int Cols) {
tempBody =(2);
iRows = Rows;
iColumns = Cols;
iCurrentRow = -1;
}
public:
T& operator[ ] (int j){
bool row_ error, column_ error;
row_ error = column_ error = false;
try {
if ( iCurrentRow < 0||iCurrentRow > = iRows)
row_ error = true;
if( j < 0||j > = iColumns)
column_error = true;
if( row_error = = true [ [ column_ error = = true)
(3);
}
catch(char) {
if (row_error = = true)
cerr < < "行下标越界"[" < < iCurrentRow < < "]";
if( colmnn_error = = true)
cerr< <"列下标越界[" < <j< <"]";
cout < < "\n";
}
return tempBody[ iCurrentRow * iColumns + j ];
}
~ Array2 DBody ( ) { delete [ ] tempBody; } }; template < class T > class Array2D {
Array2DBody < T > tBody;
public:
Array2DBody < T > & operalor[ ] (int i) {
tBody, iCurreutRow = i;
(4);
Array2D(int Rows,int Cols): (5) {} };
void main( )
{
Array2D <int> al ( 10,20 );
Array2D <double> a2(3,5);
int bl;
double b2;
b1=a1[-5][10];//有越界提示:行下标越界[-5]
b1=a1[10][15];//有越界提示:行下标越界[10]
b1=a1[1][4];//没有越界提示
b2=a2[2][6];//有越界提示:列下标越界[6]
b2=a2[10][20];//有越界提示:行下标越界[10]列下标越界[20]
b2=a2[1][4];//没有越界提示
}
第16题:
第17题:
下面的异常()为数组下标越界异常。
第18题:
研究下面的Java代码: public class testException{ public static void main(String args[]){ int a[]={0,1,2,3,4}; int sum=0; try{ for(int i=1;i<6;i++) sum=sum+a[i]; System.out.println("sum="+sum); } catch(ArrayIndexOutOfBoundsException ){ System.out.println("数组越界"); } finally{ System.out.println("程序结束");} } } 输出结果将是()。
第19题:
Java语言避免了大多数的()错误。
第20题:
程序运行时显示“下标越界”可能产生的错误有哪几种情况?
第21题:
数组下标越界
算术溢出
内存泄漏
非法的方法参数
第22题:
Arithmetic Exception
Null Pointer Exception
Array Index Out Of Bounds Exception
File Not Found Exception
第23题:
第24题:
10 数组越界 程序结束
10 程序结束
数组越界 程序结束
程序结束