UrbanPro
true

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Some Tricky Questions in C

Sahana D.
16/02/2019 0 0

Can you write two functions in which one executes before main function and other executes after the main function?

#pragma startup [priority]
#pragma exit [priority]

Where, priority is optional integer value.
For user priority varies from 64 to 255
For c libraries priority varies from 0 to 63
Default priority is 100.

pragma startup always execute the function before the main function pragma exit always execute the function after the main function. Function declaration of must be before startup and exit pragma directives and function must not take any argument and return void. If more than one startup directive then priority decides which one will execute first.

startup:
Lower value: higher priority i.e. functions will execute first. If more than one exit directive then priority decides which one will execute first.

exit:
Higher value: higher priority i.e. functions will execute first. 

Example

#include<stdio.h>

void india();
void usa() ;
#pragma startup india 105
#pragma startup usa
#pragma exit usa
#pragma exit india 105

int main(){
printf("\nI am in main");
return 0;
}

void india(){
printf("\nI am in india");
}

void usa(){
printf("\nI am in usa");
}

Output:
I am in usa
I am in India
I am in main
I am in India
I am in usa

Explanation:
Above program there are two startup directives which will execute before the main function.

Function name India has priority 105
Function name usa has priority 100 (default)

So usa function will execute first than India function and above program there are two exit directive which will execute after the main function.

Function name India has priority 105
Function name usa has priority 100 (default)

So india function will execute first than usa function.

0 Dislike
Follow 2

Please Enter a comment

Submit

Other Lessons for You

C Program-Error Handling[Program Exit Status]
//Header files #include<stdio.h>#include<conio.h>#include<stdlib.h> //Main Function void main(){ int dividend=20; int divisor=5; int quotient; //Function for clearing screen clrscr();...
S

Lets know about far, near and huge pointers for fresher interview purpose
All of these three candidates relate to 16 bit architecture where segmented memory architecture was there. They are not at all relevant for present days 32 or 64 bit architecture where the way of memory...

All About Programming And A Good Programmer.
Hi, This is my first lesson for you guys. Hope you enjoy reading it. In recent community questions, I found many people wanted to be good programmers, or wanted to have good hands on certain language,...

Basics Of C And C++
C++ is powerful, highly flexible, and adaptable programming language that allows software engineers to organise and process information quickly and effectively. But this high-level language is relatively...

Datatypes in C Language
Data types in C Language Data types specify how we enter data into our programs and what type of data we enter. C language has some predefined set of data types to handle various kinds of data that...
X

Looking for C Language Classes?

The best tutors for C Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more