#pragma startup and #pragma exit

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

#pragma startup and #pragma exit directive in c Programming Language

Syntax : startup pragma

#pragma startup <function_name> [priority]
  • startup pragma allow the program to specify function(s) that should be called upon program startup
  • Function is called before main().

Syntax : exit pragma

#pragma exit <function_name> [priority]
  • exit pragma allow the program to specify function(s) that should be called just before the program terminates through _exit.
  • Function is called after main().


  • <function_name> must be a previously declared function that takes no arguments and returns void.
  • It should be declared as –
void func(void);
  • The function name must be defined (or declared) before the pragma line is reached.


0    = Highest priority
0-63 = Used by C libraries
64   = First available user priority
100  = Default priority
255  = Lowest priority

Note :

  1. The optional priority parameter is an integer in the range 64 to 255.
  2. Do not use priorities from 0 to 63.
  3. 0-63 are used by the C libraries.
  4. Functions with higher priorities are called first at startup and last at exit.

Live Example


void School();
void College() ;

#pragma startup School 105
#pragma startup College
#pragma exit College
#pragma exit School 105

void main(){
I am in main");

void School(){
I am in School");

void College(){
I am in College");

Output :

I am in College
I am in School
I am in main
I am in School
I am in College