| | |
int main() or void main() ??!!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2006
Posts: 2
Reputation:
Solved Threads: 0
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.
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.
Last edited by Rashakil Fol; Nov 9th, 2006 at 4:00 pm.
All my posts may be redistributed under the GNU Free Documentation License.
> but she has no idea what she's teaching.
We get that a lot.
http://faq.cprogramming.com/cgi-bin/...&id=1043284376
It's only crappy DOS compilers which ever had this, presumably because DOS was so crappy at dealing with the return value that nobody ever cared.
All real compilers only accept int main, which is the only standard you should be worrying about.
We get that a lot.
http://faq.cprogramming.com/cgi-bin/...&id=1043284376
It's only crappy DOS compilers which ever had this, presumably because DOS was so crappy at dealing with the return value that nobody ever cared.
All real compilers only accept int main, which is the only standard you should be worrying about.
•
•
•
•
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.
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::. "Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
What about crappy MSV-whatever? It allows
I cared -- and used the return value all the time in .BAT files.
Absolutely... Anyone tells you different, smile knowingly, and deck them! Then have them talk to Salem....
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.
•
•
•
•
All real compilers only accept int main, which is the only standard you should be worrying about.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
Join Date: Oct 2006
Posts: 57
Reputation:
Solved Threads: 2
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
![]() |
Similar Threads
- void main vs int main (C++)
Other Threads in the C++ Forum
- Previous Thread: What's Wrong with my Array?
- Next Thread: Turbo C doubt
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






