摘要: 1.C语言中,使用malloc/calloc分配空间后,检查分配是否成功的方法是:判断返回值是否为NULL。例如:int *a = malloc(SIZE);if (a == NULL) return -1;2.标准C++中new失败默认抛出std::bad_alloc异常,故检查返回值的方法无效,正确的方法是:用try,catch捕获异常。例如:try{ int *a = new int[SIZE];}catch (std::bad_alloc &e){ std::cout << e.what() << std::endl; return -1;}3.标准C+ 阅读全文
posted @ 2014-03-22 22:28 任者 阅读(1047) 评论(0) 推荐(0) 编辑