Simple C program question

Hewlett-packard / Presario v5000 (re312ea#a...
March 26, 2009 at 00:35:51
Specs: Microsoft Windows XP Home Edition, 1.596 GHz / 1014 MB
Why does main have a return value? What is the purpose of this value?(where and when is it used?)

See More: Simple C program question

Report •

March 26, 2009 at 03:41:39
If you embed your C executable in a script , e.g. a batch, you can check the return code to keep track of program execution; see the following

Cprog /T HostName
if not errorlevel 1 echo Connection established

where Cprog.exe returns 0 if no failure occurred while running, otherwise a return code greater or equal to 1 is posted.

The return code can be inspected in case of running the program inside another one, see the C system() function.

Main's return code is the legacy of your just ended run leaving you a message about what happened.

Report •

April 14, 2009 at 04:26:23
The basic purpose of returning any value from any function is to check that is that function executed successfully or not.
If your functions executed successfully return 0 or for exception return 1. this can be handled by try...cattch . Finally main() is also a function for system calls from where program is start to execute. Suppose you calling this exe in another application... it will useful to check that, this program executed properly or not.

Report •

Related Solutions

Ask Question