473,396 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Difference between using exit(n) and return n in main()?

What is the difference between using exit(n) and return n in main(), if
any? I know that exit(n) is a function that exits and return n exits via a
return value, but is there any reason to specify one rather than the
other? Thanks!
Nov 13 '05 #1
2 10975
On Mon, 17 Nov 2003 01:43:32 GMT, "fwee" <no****@nospam.com> wrote in
comp.lang.c:
What is the difference between using exit(n) and return n in main(), if
any? I know that exit(n) is a function that exits and return n exits via a
return value, but is there any reason to specify one rather than the
other? Thanks!


This is a FAQ:

11.16 Is exit(status) truly equivalent to returning the same status
from main?

See http://www.eskimo.com/~scs/C-faq/q11.16.html

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #2
fwee wrote:
What is the difference between using exit(n) and return n in main(), if
any? I know that exit(n) is a function that exits and return n exits via a
return value, but is there any reason to specify one rather than the
other? Thanks!

Exit exit the program with n status no matter how deeply you've recursed
in functions.

Example:

int blah (void)
{
return 1;
/* exit(1) would actually exit the program here, whereas return
does not */
}

int main (void)
{
blah();
return 0;
/* exit(0) and return have pretty much the same function in this
context */
}

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
by: Mike Machuidel | last post by:
Hi, I'm a game developer programming mostly in C and ASM for about 7 years. Today at work a colleague (a C++ programmer) yelled at me I'm a bad C programmer because I use "return(0);" instead...
5
by: Larry Bird | last post by:
I want to use TimeSpan to determine the differences between two date to include time. My input data is in the following format: 12/25/2004 12:23:00 AM or 01/05/2005 11:59:00 PM How do I get...
6
by: Gary Wessle | last post by:
Hi I read an example provided by Big Bucks Inc. no how to use their library. in it they have some thing like string doit(){ /* ... */ cout << "doit called" << endl; } int main(){ doit(); }
1
by: vishalsharma | last post by:
hi can any body explain what is the difference between carriage return (\r) or you can say Enter and New Line character(\n).. both are treated as same.. in .net(c#) if you write a file...
37
by: Army1987 | last post by:
Is that in the object line a conforming program? If so, why? If not, why? I'd expect it to be much like int main(void) { for (;;); } But if I compile it with lcc-win32 and run it in its...
2
nabh4u
by: nabh4u | last post by:
hi friends, i have a probelm with finding the bit difference using xor. i have 2 strings and i have to convert the first tring into another. in order to convert i should get the cost by finding...
15
by: Pixel.to.life | last post by:
Dear All, Here is a problem I am facing (it might be too simple, but then I admit I am not a Guru:-) I have a main thread, in managed C++, that deals with displaying a form and some controls....
3
by: simritsaini1982 | last post by:
Hello.. Can anybody explain that how member functions of a class has direct access to the data members of the class vidout any need to declare them locally in the function body. As in main() we...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.