首页 > 其他 > 详细

第十六周 程序阅读

时间:2015-06-27 16:26:57      阅读:123      评论:0      收藏:0      [点我收藏+]
#include <iostream >
using namespace std;
int a[10]= {1,2, 3, 4, 5, 6, 7, 8, 9, 10};
int fun( int i);
int main()
{
    int i ,s=0;
    for( i=0; i<=10; i++)
    {
        try
        {
            s=s+fun(i);
        }
        catch(int)
        {
            cout<<"数组下标越界!"<<endl;
        }
    }
    cout<<"s="<<s<<endl;
    return 0;
}
int fun( int i)
{
    if(i>=10)
        throw i;
    return a[i];
}


运行结果:

技术分享

版权声明:本文为博主原创文章,未经博主允许不得转载。

第十六周 程序阅读

原文:http://blog.csdn.net/ljd939952281/article/details/46661693

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!