- World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Interview Success Kit - 9,000 Interview Que. & Ans.
Covers 9,000+ Interview Questions asked in actual MNC Interviews - all with model answers.
Get Your Dream Job Now -
Sponsored Links
Interview Questions
Our Services

Question :
Is using exit() the same as using return?
Category Functions in C Interview Questions
Rating (4.4) By 57 users
Added on 10/22/2009
Views 6035
Rate it!

No. The exit() function is used to exit your program and return control to the operating system. The return statement is used to return from a function and return control to the calling function. If you issue a return from the main() function, you are essentially returning control to the calling function, which is the operating system. In this case, the return statement and exit() function are similar.

Prototype of atexit() is :
int atexit ( void ( * function ) (void) );

The function pointed by the function pointer argument is called when the program terminates normally.

If more than one atexit function has been specified by different calls to this function, they are all executed in reverse order as a stack, i.e. the last function specified is the first to be executed at exit.

One single function can be registered to be executed at exit more than once.

/* atexit example */
#include <stdio.h>
#include <stdlib.h>

void fnExit1 (void)
puts ("Exit function 1.");

void fnExit2 (void)
puts ("Exit function 2.");

int main ()
atexit (fnExit1);
atexit (fnExit2);
puts ("Main function.");
return 0;


Main function.
Exit function 2.
Exit function 1.

//Here the output is in reverse order as a stack, i.e. the last function specified is the first to be executed at exit.

Posted by: Syed Baseer Ahmed

Contact Syed Baseer Ahmed Contact Syed Baseer Ahmed

exit() is used for to exit the control from the program. but return() return the values to main or functions. it never terminate the program.

Posted by: aravind

Contact aravind Contact aravind

Exit and return serves differnt purposes.
Exit is used to terminate the calling program while return is used to return the value to calling program
int sum(int a, int b);
int a,b,c;
printf("Enter the value of a and b);
scanf("%d %d",&a,&b);
printf("Sum is %d",c);
int sum(int a, int b)
int d;
in this bcause of exit function the output will not be displayed but if we delete line exit(0) then we will get output

Posted by: Ruchi

Contact Ruchi Contact Ruchi

If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in

  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
  • 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
    Differentiate between a linker and linkage?
    View Answer
    What is a function and built-in function?
    View Answer
    What is an argument ? differentiate between formal arguments and actual arguments?
    View Answer
    What is the purpose of main( ) function?
    View Answer
    What are the advantages of the functions?
    View Answer
    What is a method?
    View Answer

    Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here - Best Freshers & Experienced Jobs Website.

    View ALL Functions in C Interview Questions & Answers

    User Options
    Latest 20 Questions
    What are the common properties Button controls used in ASP.NET?
    How to apply themes for application?
    What is the use of "HttpHandlers" in web.config ?
    What?s the difference between Linkbutton control and Hyperlink control?
    In ASP.NET how many navigation controls are there?
    List all different typesS of directives in .NET
    What are the State Management options in ASP.NET ?
    What is Global Assembly Cache ?
    What is the difference between ExecuteScalar and ExecuteNonQuery?
    What is the appSettings Section in the web.config file?
    List the major built-in objects in ASP.NET?
    What are the Security Controls?
    Explain the working of passport authentication.
    How can we apply Themes to an application?
    What are the event handlers that we can have in Global.asax file?
    Write code to send e-mail from an ASP.NET application?
    What are the different validators in ASP.NET?
    How to execute an sql query? How to fetch its result ?
    What is the difference between Session and Cookie?
    What are different types of Runtime Errors in PHP?

    Copyright ©2003-2016, All Rights Reserved.
    Privacy Policy | Terms and Conditions

    Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Dedicated Servers | C Interview Questions & Answers

    Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

    Cache = 0.003906 Seconds