NullpointerException
ArithmeticExceptioin
ArrayIndexOutOfBoundsException
SecurityManager
第1题:
A.NullpointerException
B.ArithmeticExceptioin
C.ArrayIndexOutOfBoundsException
D.SecurityManager
第2题:
对高级语言源程序进行编译时,可发现源程序中的(21)错误。
A.堆栈溢出
B.变量未定义
C.指针异常
D.数组元素下标越界
第3题:
A.ArithmeticException
B.IOException
C.ArrayIndexOutOfBoundsException
D.NullPointerException
第4题:
以下程序执行的结果是什么?()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.程序编译出错
第5题:
阅读以下程序说明和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]; //没有越界提示
}
第6题:
●对高级语言源程序进行编译时,可发现源程序中的(8)错误。
(8)A.堆栈溢出
B.变量未定义
C.指针异常
D.数组元素下标越界
第7题:
试题(21)
对高级语言源程序进行编译时,可发现源程序中的 (21) 错误。
(21)
A. 堆栈溢出
B. 变量未定义
C. 指针异常
D. 数组元素下标越界
试题(21)分析
本题考查编译过程基本知识。
高级语言源程序中的错误分为两类:语法错误和语义错误,其中语义错误又可分为静态语义错误和动态语义错误。语法错误指语言结构上的错误,静态语义错误指编译时就能发现的程序含义上的错误,动态语义错误只有在程序运行时才能表现出来。堆栈溢出、指针异常和数组元素下标越界都是程序运行中才能出现的问题,而遵循先声明后引用原则的程序语言必须先定义变量,然后才能使用,否则编译器会在语法分析阶段指出变量未定义错误。
参考答案
(21)B
第8题:
研究下面的Java代码:publicclasstestException{publicstaticvoidmain(Stringargs[]){inta[]={0,1,2,3,4};intsum=0;try{for(inti=1;i<6;i++)sum=sum+a[i];System.out.println("sum="+sum);}catch(ArrayIndexOutOfBoundsException){System.out.println("数组越界");}finally{System.out.println("程序结束");}}}输出结果将是()。
A.10数组越界程序结束
B.10程序结束
C.数组越界程序结束
D.程序结束
第9题:
阅读下列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]; //没有越界提示
}
第10题:
阅读下列说明和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];//没有越界提示
}