Computing.Net > Forums > Programming > Simple C program question

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Simple C program question

Reply to Message Icon

Name: netmeter
Date: March 26, 2009 at 00:35:51 Pacific
OS: Microsoft Windows XP Home Edition
CPU/Ram: 1.596 GHz / 1014 MB
Product: Hewlett-packard / Presario v5000 (re312ea#abv)
Subcategory: C/C++
Comment:

Why does main have a return value? What is the purpose of this value?(where and when is it used?)



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: March 26, 2009 at 03:41:39 Pacific
Reply:

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.


0

Response Number 2
Name: sandipkalle
Date: April 14, 2009 at 04:26:23 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Simple C program question

C Program Simple Question (HELP...) www.computing.net/answers/programming/c-program-simple-question-help/10559.html

C Programming Question www.computing.net/answers/programming/c-programming-question/13567.html

simple C++ compile problem in Linux www.computing.net/answers/programming/simple-c-compile-problem-in-linux-/1282.html