473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

2 very basic qns

1. Why does C++ require the int in:
int main(){...}
(is there a special reason for int, why not void,etc...?)

2. What purpose does the return 0; serve at the end of the main
program:
(when the program is run successfully and the " return 0; " statement
is encountered, what exactly happens -- where is the 0 returned?)

thanks
Jul 22 '05 #1
5 1137

"mescaline" <ap*****@columbia.edu> wrote in message news:e5**************************@posting.google.c om...
1. Why does C++ require the int in:
int main(){...}
(is there a special reason for int, why not void,etc...?)
Are you talking about main specifically or functions in general. The "implicit"
int return has been removed from the language because it wasn't exactly consistant.

As far as why MAIN itself must return int. Tradition is the major reason.

2. What purpose does the return 0; serve at the end of the main
program:
(when the program is run successfully and the " return 0; " statement
is encountered, what exactly happens -- where is the 0 returned?)

It's an implementation specific success code. On some systems it gets
passed back to the invoked program (like UNIX). On some systems
the environment calls a system call indicating normal termination where as
the error returns from exit/main call the error system call. On others a
zero means silent exit while a non-zero return cause an error popup.
Others the value is just discarded.
Jul 22 '05 #2
"Ron Natalie" <ro*@sensor.com> wrote in message
news:3f***********************@news.newshosting.co m...

"mescaline" <ap*****@columbia.edu> wrote in message news:e5**************************@posting.google.c om...
1. Why does C++ require the int in:
int main(){...}
(is there a special reason for int, why not void,etc...?)


Are you talking about main specifically or functions in general. The

"implicit" int return has been removed from the language because it wasn't exactly consistant.
As far as why MAIN itself must return int. Tradition is the major

reason.

Well, not really. The standards group, that works on defining the language,
has published a standard that main must return an int.
Unless you want to call standards a tradition...
--
Gary
Jul 22 '05 #3

"Gary Labowitz" <gl*******@comcast.net> wrote in message news:3-********************@comcast.com...
Well, not really. The standards group, that works on defining the language,
has published a standard that main must return an int.
Unless you want to call standards a tradition...
--

I know that. The poster asked for WHY. The language is defined by the
standard, but the standards people had reasons for the requirements they
set down. The reason main is REQUIRED BY THE STANDARD
to return in is TRADITION. Main has always returned int, ever since
the early days of C. Partially this was because C didn't even have a void
type in the beginning, then later because UNIX relied heavily on using the
numeric return from programs.

Jul 22 '05 #4
"Gary Labowitz" <gl*******@comcast.net> wrote in message news:<3-********************@comcast.com>...
"Ron Natalie" <ro*@sensor.com> wrote in message
news:3f***********************@news.newshosting.co m...

"mescaline" <ap*****@columbia.edu> wrote in message

news:e5**************************@posting.google.c om...
1. Why does C++ require the int in:
int main(){...}
(is there a special reason for int, why not void,etc...?)


Are you talking about main specifically or functions in general. The

"implicit"
int return has been removed from the language because it wasn't exactly

consistant.

As far as why MAIN itself must return int. Tradition is the major

reason.

Well, not really. The standards group, that works on defining the language,
has published a standard that main must return an int.
Unless you want to call standards a tradition...

Conversely, does it always return a non-zero value, when there's *any*
error with the compiling?

thanks
Jul 22 '05 #5

"mescaline" <ap*****@columbia.edu> wrote in message news:e5**************************@posting.google.c om...
Conversely, does it always return a non-zero value, when there's *any*

error with the compiling?


If you had problems compiling, you're not likely going to get as far as
having a main function to run.

Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
9
by: Malcolm | last post by:
After some days' hard work I am now the proud possessor of an ANSI C BASIC interpreter. The question is, how is it most useful? At the moment I have a function int basic(const char *script,...
56
by: Dave Vandervies | last post by:
I just fixed a bug that some of the correctness pedants around here may find useful as ammunition. The problem was that some code would, very occasionally, die with a segmentation violation...
14
by: luis | last post by:
Are basic types (int, long, ...) objetcs or not? I read that in C# all are objects including basic types, derived from Object class. Then in msdn documentation says that boxing converts basic...
3
by: sefe dery | last post by:
hi ng, i try to create a asp.net 1.0 website on windows server 2003(Servername: ServerX) with iis 6.0. PROBLEM: The user should login with his windows credentials in basic.aspx and...
13
by: usenet | last post by:
How and where can one find out about the basics of VB/Access2003 syntax? I am a died in the wool C/C++/Java Linux/Unix programmer and I am finding it difficult to understand the program format...
10
by: trippeer | last post by:
I have the source code to an old BASIC program that a friend of mine would like to run online. I am a beginner at JS, but I think that it would be a good choice for the project. My background is in...
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
111
by: Enteng | last post by:
Hi I'm thinking about learning C as my first programming language. Would you recommend it? Also how do you suggest that I learn it?What books/tutorials should I read for someone like me? Thanks...
6
by: Simon Walsh | last post by:
I'm an Electronics student in college and I'm currently working on a project. I was given a circuit diagram for my project, from which I had to design a printed circuit board to be sent off and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.