User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:stdlib.h:exit

exit

    #include <stdlib.h>
    void exit(int status);

exit causes the termination of a program.
To the environment in which the program was started, a return code will be sent.

exit C Sourcecode Example

/* 
 * exit c example code
 * http://code-reference.com/c/stdlib.h/exit 
 */
#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
 
#include <stdlib.h>
 
int exittest ( int testval )
{
   if (testval == 3 ) {  exit (1); }
return 0;
}
 
int main( void )
{
 int i;
 
/* comment this in to see what happen */
// exit(0); 
 
 for (i=0;i<=99;i++) {
     exittest(i);
     printf("%i\n", i);
  }
 
return 0;
}

Output with commented exit(0) before the for loop

  user@host:~$ ./exit
  0
  1
  2

Output with out commented exit(0) before the for loop

  user@host:~$ ./exit

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdlib.h/exit.txt · Last modified: 2024/02/16 01:04 (external edit)

Impressum Datenschutz