It has to do with the C++ standard. The standard says, "use int", so that's what you should use. The reason you should use int is, void main is not necessarily accepted by every compiler.
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 176
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
that it doesnt like having ".h" in the end of header files as in . I figured out why "using namespace std" is used.
Your teacher is teaching such old and outdated coding styles. iostream replaced iostream.h like 10 years ago, and since then, you should either use "using namespace std;" or prefix any standard template objects with std:: .
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
Using void usually means it wont return an integer value.
No -- main() will return an int whether you declare it void or not. If you declare it void then main() will return some random unpredictable integer.
Ancient Dragon
Retired & Loving It
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
It's only crappy DOS compilers which ever had this,
What about crappy MSV-whatever? It allows void main() without a problem to this day, doesn't it? And OS/2's compiler didn't complain, either, if memory serves....presumably because DOS was so crappy at dealing with the return value that nobody ever cared.
I cared -- and used the return value all the time in .BAT files.All real compilers only accept int main, which is the only standard you should be worrying about.
Absolutely... Anyone tells you different, smile knowingly, and deck them! Then have them talk toSalem.... :twisted:
WaltP
Posting Sage w/ dash of thyme
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943
int main() is used to return 0 at the end. This 0 is returned to the Operating system to denote that the function main() - which is the only function called by the operating system and that's why its so special - has completed successfully. Always use int main() and return 0 at the end of it. Dont use void
may4life
Junior Poster in Training
57 posts since Oct 2006
Reputation Points: 13
Solved Threads: 2