Defining Startup and Exit in C

Defining Startup and Exit in C programming by using 'startup' and 'exit' keywords. 'startup' is used to call a function after the program starts and 'exit' is used to call a function before the program terminates.

Defining Startup and Exit

'#pragma startup' and '#pragma exit': These directives allow us to specify functions that are called upon program startup (before main( )) or program exit (just before the program terminates).

Program

#include<stdio.h>
#include<conio.h>
void fun1();
void fun2();
void fun3();
#pragma startup fun1 //defining calling 'fun1()' and 'fun2()' function
#pragma startup fun2 //when Program start.
#pragma exit fun3 //defining calling 'fun3()' function when program
void main()       //exiting.
{
getch();
}
void fun1()
{
printf("Inside fun1");
}
void fun2()
{
printf("\nInside fun2");
}
void fun3()
{
printf("\nInside fun3");
}
Output
Inside fun1
Inside fun2