C Reference function exit()

The function exit() will terminate the process that calls the exit.

Usage of exit():

void exit ( int status );

On call the process will terminate normally. It will perform regular cleanup as normal for a normal ending process. (For example atexit functions are executed.)


A status value returned to the parent process.

Return value:

The argument status is returned to the host environment.
Normally you say 1 or higher if something went wrong and 0 if everything went ok. For example exit(o) or exit (1).

Source code example of exit():


	int main ()
		int * buffer;

		/*get a initial memory block*/
		buffer = (int*) malloc (10*sizeof(int));
		if (buffer==NULL)
			printf("Error allocating memory!");
			exit (1);

		free (buffer);
		return 0;

This entry was posted in C Reference stdlib.h Functions. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed. Tweet This! Tweet This! or use to share this post with others.

There is currently one response to “C Reference function exit()”

Why not let us know what you think by adding your own comment!

  1. @vijaynitj on February 1st, 2013:

    thnk you so much for such beautiful effort…