void abort(void)
原型位於 stdlib.h, process.h
適用於 UNIX 系統,在 ANSI C 中有定義
該函數將終止信息 “Abnormal program termination" 寫入 stderr 中, 並通過調用帶有終止碼 3 的
_exit 來終止程序。
abort 將把終止碼 3 返回給父進程 或 DOS
#include<stdio.h>
#include<stdlib.h>
int main()
{
printf(" Calling abort()/n");
abort();
/* this is never reached */
printf(" You'll never see this/n");
return 0;
}
運行結果如圖:
_exit 終止程序
void _exit(int status)
原型位於 stdlib.h, process.h
適用於 UNIX 系統,在 ANSI C 中有定義
_eixt 終止調用進程, 但不關閉文件, 不清除輸出緩存,也不 調用出口函數。
調用進程 時用 status 作爲出口狀態,一般來說, 0 表示正常出口, 非 0 值表示有錯誤發生。
沒有返回值
#include<stdio.h>
#include<stdlib.h>
int main()
{
printf(" Calling abort()/n");
_exit(3);
/* this is never reached */
printf(" You'll never see this/n");
return 0;
}
結果如圖: