Dotcpp  >  编程教程  >  stdlib.h头文件  >  C语言exit()函数:用于正常终止程序

C语言exit()函数:用于正常终止程序

点击打开在线编译器,边学边练

函数名:exit

头文件:<stdlib.h>

函数原型: void exit(int status);

功能:用于正常终止程序

参数:int status  为终止状态

返回值:没有返回值    


程序例:使用该函数正常终止一个程序,其后面的语句将不被执行。

#include<stdio.h>

#include<stdlib.h>

int main(void){

   int a,status;

   printf("Input a order: 1--go  others--exit\n");

   while(scanf("%d",&a)==1){

      if(a!=1){

         exit(0);

      }

      printf("Input a order: 1--go  others--exit\n");   

   }

   return 0;

}


运行结果

Input a order: 1--go  others--exit
1
Input a order: 1--go  others--exit
1
Input a order 1--go  others--exit
3



本文固定URL:https://www.dotcpp.com/course/551

C语言函数库
assert.h头文件
ctype.h头文件
float.h头文件
io.h头文件
math.h头文件
mem.h头文件
setjmp.h头文件
stdio.h头文件
stdlib.h头文件
sigal.h头文件
string.h头文件
time.h头文件
Dotcpp在线编译      (登录可减少运行等待时间)