exit()- Utility Function

How is Utility Function "exit()" used in C++?
How to terminate the program using c++?


exit() is a Utility Function that causes the program to terminate normally . An exit_code is passed to the calling program, if this is "0" or EXIT_SUCCESS it is normal termination. If the exit_code is non-zero or EXIT_FAILURE indicates an error.


void exit (int exit_code);

Example :

#include <stdlib.h>
#include <stdio.h>
int main ()
printf ("Print text");
exit (1);
printf("Will not be displayed");
return 0;

Result :

Print text

In the above example exit() function terminates the program, after the first "printf" statement is executed.

C++ Tutorial

Ask Questions

Ask Question