 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Antonio Parolini Guest
|
Posted: Tue Dec 19, 2006 10:10 am Post subject: What is the difference ? |
|
|
What is the difference between:
main(......) {
exit(0);
}
and
main(......) {
return(0);
}
Thank you! |
|
| Back to top |
|
 |
Andre Kostur Guest
|
Posted: Tue Dec 19, 2006 10:10 am Post subject: Re: What is the difference ? |
|
|
"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
|
Posted: Tue Dec 19, 2006 10:10 am Post subject: Re: What is the difference ? |
|
|
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 |
|
 |
|
|
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
|
|