C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

What is the difference ?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Antonio Parolini
Guest





PostPosted: Tue Dec 19, 2006 10:10 am    Post subject: What is the difference ? Reply with quote



What is the difference between:

main(......) {

exit(0);
}

and

main(......) {

return(0);
}

Thank you!
Back to top
Andre Kostur
Guest





PostPosted: Tue Dec 19, 2006 10:10 am    Post subject: Re: What is the difference ? Reply with quote



"Anant" <anant.kumar (AT) gmail (DOT) com> wrote in news:1166510526.110605.230050@
73g2000cwn.googlegroups.com:

Quote:
If you are calling some function recursively then return 0 will just go
to one level down on the stack, while exit 0 will terminate this
thread.

Also, as I recall, if you do an exit(0) from main() instead of return(0),
global variables (and I suspect variables local to main()) will not get
destructed. exit(0) means for your program to die now, no chance to clean
up after itself.
Back to top
Anant
Guest





PostPosted: Tue Dec 19, 2006 10:10 am    Post subject: Re: What is the difference ? Reply with quote



If you are calling some function recursively then return 0 will just go
to one level down on the stack, while exit 0 will terminate this
thread.

int f(int i)
{
if (i == 3)
{
return 0;;
}
f(i+1);
cout <<" the value is "<<i<<endl;
}
int main(void)
{
f(0);
return 0;
}

OUTPUT >> the value is 2
the value is 1
the value is 0

while

int f(int i)
{
if (i == 3)
{
exit (0);
}
f(i+1);
cout <<" the value is "<<i<<endl;
}
int main(void)
{
f(0);
return 0;
}

will just return with out printing anything. Even if we will create one
object inside this function "f", it will not call destructor of this
object.While in the first program it will call the destructor of of the
object.

Antonio Parolini wrote:
Quote:
What is the difference between:

main(......) {

exit(0);
}

and

main(......) {

return(0);
}

Thank you!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.