Well, first of all, I'm astrojith. I'm new here at Daniweb. So, hello all of you :cheesy: !! . Now, to my question. In school, I'm being taught programs which all use "void main()". But, I've seen a lot of code using int main(). I asked my teacher about this but she has no idea what she's teaching. She told me "Because its the way it should be done " . I said(to myself), " What the heck !? " Without any reason ? There should be a reason for everything. So, can anybody tell me ?

Well, I've one more question. I'm presently using Turbo C++ IDE to code. I tried using Dev-C++ yesterday and I found out that it doesnt even accept void main() and that it doesnt like having ".h" in the end of header files as in <iostream.h>. I figured out why "using namespace std" is used. But, I cant figure out the other doubts. Pls help me.

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.

that it doesnt like having ".h" in the end of header files as in <iostream.h>. 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:: .

Using int for a function isually means it returns an integer value.
Using void usually means it wont return an integer value.

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.

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 to Salem.... :twisted:

Oh, and I thought they were the same. That teacher doesnt know what sh's teaching. But, well, no other choice I guess. Thank y'all for telling me this.

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

This article has been dead for over six months. Start a new discussion instead.