| | |
void main() and int main()
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
> is there any advantage in using int main() over void main()?.
-- Stroustrup
> when you return a value in int main(), where does the returned value go?
-- Stroustrup
•
•
•
•
The definitionvoid main() { /* ... */ }is not and never has been C++, nor has it even been C. See the ISO C++ standard 3.6.1[2] or the ISO C standard 5.1.2.2.1. A conforming implementation accepts
int main() { /* ... */ }and
int main(int argc, char* argv[]) { /* ... */ }A conforming implementation may provide more versions of main(), but they must all have return type int.
> when you return a value in int main(), where does the returned value go?
•
•
•
•
The int returned by main() is a way for a program to return a value to "the system" that invokes it. On systems that doesn't provide such a facility the return value is ignored, but that doesn't make "void main()" legal C++ or legal C. Even if your compiler accepts "void main()" avoid it, or risk being considered ignorant by C and C++ programmers.
Link with FAQs and other information
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.
•
•
•
•
Is the advice different for devices that do not necessarily have an operating system.
Like embedded devices though?
Last edited by Ancient Dragon; Feb 16th, 2008 at 10:00 am.
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.
>Is the advice different for devices that do not necessarily have an operating system.
Freestanding implementations are excepted from a lot of the rules of hosted implementations. But since a programmer on a freestanding implementation is highly unlikely to be asking this question, and int main is always correct, the advice stands.
Freestanding implementations are excepted from a lot of the rules of hosted implementations. But since a programmer on a freestanding implementation is highly unlikely to be asking this question, and int main is always correct, the advice stands.
New members chased away this month: 3
![]() |
Similar Threads
- void main vs int main (C++)
- accessing data members from outside main() (C++)
- Embedded main() (C++)
- Problem with string variable in void prnt function (C++)
Other Threads in the C++ Forum
- Previous Thread: Array/ Recursive Problem
- Next Thread: c++ Hardware
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






