What happens to '0'???

Solved/Closed
darani - Apr 2, 2008 at 11:14 PM
 darani - Apr 11, 2008 at 07:53 AM
Hello,
I have been wondering for a long time about the return statement in the c-programming. Now consider the following code....

int main()
{
.............
return(0);
}

I would like to know where does the value zero(0) go???

Any function's return statement will return the value to it's calling function. Then what is it for main()???

have a gr8 day
bye tc
Related:

6 responses

crazy_devil Posts 124 Registration date Wednesday February 20, 2008 Status Member Last seen February 6, 2009 20
Apr 3, 2008 at 03:18 PM
lol Thats like chinese to me ^^

Soory cant help this hehee

Take care darani ;0P
0
kilian Posts 8731 Registration date Thursday September 18, 2003 Status Moderator Last seen August 20, 2016 1
Apr 3, 2008 at 07:27 PM
Hi!

Under Unix/Linux it is returned to the parent process ;-)
The return of the main is the "exit code".
It is sometimes important to determine if a child executed itself as it wanted to.
As an example, consider a shell under Linux. When an application is launched by the shell, the shell becomes the parent process, and the application launched is the child.

In this configuration, the shell will wait for the end of its child. If it terminated correctly , it will return a value (the return of the main or the value of exit if the exit function was used). And the parent (the shell) will be able able to read the exit status.
0
thnx frnd...
the answer was very useful...

if it is in other platform then????
say like windows, etc....
0
kilian Posts 8731 Registration date Thursday September 18, 2003 Status Moderator Last seen August 20, 2016 1
Apr 10, 2008 at 12:52 PM
Under Windows it is a bit different. the standard entrypoint of a windows based program is the WinMain function. As you can see, its parameters are a bit different and it's the same for its return value.

You can use the main() under windows but I guess that the compiler build itself a WinMain function that calls your main() function.

And what happens to the WinMain return value?

For example when you kill yourself a process with TerminateProcess you can examine its return code with GetExitCodeProcess to know how it terminated :-)
0

Didn't find the answer you are looking for?

Ask a question
kilian Posts 8731 Registration date Thursday September 18, 2003 Status Moderator Last seen August 20, 2016 1
Apr 10, 2008 at 12:55 PM
And under Mac Os X it is the same as in Linux, because they are both Unix-like systems.
0
Thnx frnd...
lot to know from u...

have a gr8 day
bye tc
0