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.)

Parameters:

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():


	#include<stdio.h>
	#include<stdlib.h>

	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. You can leave a response, or trackback from your own site. Tweet This! Tweet This! or use to share this post with others.

Leave a Reply: