c/c++ 程序错误记录
// 返回类型为 int ,正常执行代码就会没有返回值,引起段错误
int test(int **a) // 错误,引起段错误,且没有打印输出信息。
{
try {
*a = new int[10];
} catch (const char *msg) {
fprintf(stderr, "%s", msg);
return -1;
}
}
int test(int **a) // 正确
{
try {
*a = new int[10];
} catch (const char *msg) {
fprintf(stderr, "%s", msg);
return -1;
}
return 0;
}
// 编译可能不报错,但是会引起程序运行异常
int test(int **a)
{
*a = new int[10];
}