Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-25-2003, 10:37 PM   #1
Registered: Oct 2003
Distribution: woodY 3.0 stable
Posts: 61

Rep: Reputation: 15

int main() {......
return(0); // Why i should return 0 and not 1 or 2 ?
Old 10-25-2003, 11:05 PM   #2
Registered: Aug 2003
Location: Hyderabad, India
Posts: 126

Rep: Reputation: 15
You can return 1 or 2...or any integer.
Old 10-25-2003, 11:27 PM   #3
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
Returning anything from main is usually insignificant. Though it's proper to return 0, since it tells the OS that the program terminated properly.
Old 10-25-2003, 11:28 PM   #4
Registered: Oct 2003
Distribution: woodY 3.0 stable
Posts: 61

Original Poster
Rep: Reputation: 15
but the meaning is the same? : return(0) return(1) return(n)
Old 10-26-2003, 12:31 AM   #5
Jose Muņiz
Registered: Jul 2003
Location: Mexico City
Distribution: Slackware 9.1, SuSE 9.1
Posts: 248

Rep: Reputation: 32
main() is a function. A function is a piece of code that does certain tasks with information they receive, and that gives out certain information.

Suppose you are a boss and you tell one of your employees to do something, and you give him some materials to work with (arguments). He will then go and do whatever process he needs and will come to you with the result (returned to you via the return statement).

So... a function in C has the following parts:

variable_returned name_of_function(parameters)
return statement;

variable_returned indicates the type of variable that will be returned, say, an integer. Hence... in the function, if you return 3, for instance... the instance that called your function will receive value 3. Let's look at an example:

int returnsThree()
return 3;

int main()

int variable;

variable = returnsThree();
return 0;

The value of variable will be 3.

Now, in int main(), the return statement helps the operating system to know whether the program did a normal exit or not. Suppose you interrupted it... then, you will be able to see that its exit code is something different to 0... in that way, the return statement helps you to know what kind of exit took place.

I hope I was clear enough :P And sorry if there's any syntax error in my previous code :P I haven't programmed in C for like 3 months


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
dd return code barefootdoctor Linux - General 2 10-13-2005 01:54 PM
return value neerajchaudhari Linux - Newbie 1 08-29-2005 02:42 AM
application return value prital Linux - Newbie 1 03-30-2005 10:29 AM
return to ntfs eyedoc General 4 03-19-2005 10:23 PM
return 0 or return(0) in C? servnov Programming 5 01-08-2005 05:39 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:11 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration