河南成教 / 面向对象程序设计
25[分析题]
#include <iostream.h>int a[ 10 ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };int fun( int i );void main(){ int i ,s = 0; for( i = 0; i <= 10; i ) { try { s = s fun( i ) ; } catch( int ) { cout << "数组下标越界!" << endl; } } cout << "s = " << s << endl;}int fun( int i ){ if ( i >= 10 ) throw i ; return a[i] ;}
25[分析题]
#include <iostream.h>int a[ 10 ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };int fun( int i );void main(){ int i ,s = 0; for( i = 0; i <= 10; i ) { try { s = s fun( i ) ; } catch( int ) { cout << "数组下标越界!" << endl; } } cout << "s = " << s << endl;}int fun( int i ){ if ( i >= 10 ) throw i ; return a[i] ;}
参考答案:
佳题速递: