CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C DETAILS
Question :
Is it possible to execute code even after the program exits the main() function?
Category C Interview Questions
Rating (4.5) By 74 users
Added on 10/22/2004
Views 12605
Rate it!
Answers:

The standard C library provides a function named atexit() that can be used to perform ?cleanup? operations when your program terminates. You can set up a set of functions you want to perform automatically when your program exits by passing function pointers to the at exit() function.



This can be done by using #pragma directive as:
#pragma exit <function name>

Using above code, any function can be executed after program exits the main function but function must be declared before pragma directive is reached.



 Posted by: Navneet Singh    

Contact Navneet Singh  Contact Navneet Singh

To be more precise, atexit is used to register the exit functions which will be called upon upon exit from main(). I also remember that upto 42 functions can be registered using atexit(). I don't know what this "magical" number is chosen, though.
e.g:
atexit(Bye1);
atexit(Bye2);
..
atexit(Bye42);

where Bye1,Bye2,..Bye42 will be called in succession.



 Posted by: Hemanth    

Contact Hemanth  Contact Hemanth


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
Is using exit() the same as using return?
View Answer
Can the sizeof operator be used to tell the size of an array passed to a function?
View Answer
Is it better to use a pointer to navigate an array of values,or is it better to use a subscripted array name?
View Answer
What is the difference between a string and an array?
View Answer
What is a modulus operator? What are the restrictions of a modulus operator?
View Answer
Why n++ executes faster than n+1?
View Answer
Write the equivalent expression for x%8?
View Answer
Which expression always return true? Which always return false?
View Answer
What is storage class and what are storage variable ?
View Answer
What are the advantages of auto variables?
View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/988/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.67