w3resource logo

:

C Programming Exercises

C Exercises: Set a function that will be executed on termination of a program

C Variable Type : Exercise-15 with Solution

Write a C program to set a function that will be executed on termination of a program.

Sample Solution:

C Code:

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

void newFunctionOne (void)
	{
		puts (" Here is the message returning from newFunctionOne.");
	}
	void newFunctionTwo (void)
	{
		puts (" Here is the message returning from newFunctionTwo.");
	}
	int main ()
	{
		atexit (newFunctionOne);
		atexit (newFunctionTwo);
		puts ("\n This is the message from main function.");
		return 0;
	}

Sample Output:

 This is the message from main function.                                                                      
 Here is the message returning from newFunctionTwo.                                                           
 Here is the message returning from newFunctionOne

C Programming Code Editor:

Improve this sample solution and post your code through Disqus