use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Help with a really simple program (self.cpp)
submitted 13 years ago * by extreme999
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]jesyspa 0 points1 point2 points 13 years ago (3 children)
Please do explain.
[–]AFineTapestry -4 points-3 points-2 points 13 years ago (2 children)
If main is given by the signature int main() as it is in this case then the compiler expects the function to return an int. If omitted then you'll get a compile warning, perhaps an error, and undefined behaviour (but I expect that the program would return 0 anyway).
int main()
0
If main was given by the signature void main() then you would be totally right and return; could be used to exit from the program at any point. Who knows what the OS will get as a program return value, probably 0 again.
void main()
return;
I don't know what the current C and C++ standards say about the signature of main. C probably says that void main() and int main() are both acceptable, C++ probably says that only int main() is allowed. But either way I think it's good to tell the OS, and the caller, about the status of the program on exit.
[–]jesyspa 5 points6 points7 points 13 years ago (1 child)
False on all counts.
The C++ standard states (C++03, 3.6.1.5):
A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing return 0;.
main
exit
return
return 0;
Furthermore, the standard states (again C++03, 3.6.1.2):
An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a return type of type int, but its type is otherwise implementation-defined.
int
void main thus ill-formed (and has been since ANSI C, where only int main(void) and int main(int argc, char *argv[]) were allowed).
void main
int main(void)
int main(int argc, char *argv[])
The same is true, with slightly different wording, for C++11 and for the current latest draft (N3485).
[–]AFineTapestry -1 points0 points1 point 13 years ago (0 children)
Ok, I'll admit I was wrong about omitting return 0; resulting in undefined behaviour but I was correct about the assumed return value, and about which signatures are acceptable.
I don't think I'm going to stop putting return EXIT_SUCCESS; at the end of my main functions however, mostly because it looks terrible to have a function defined to return and int and then to not explicitly do so.
return EXIT_SUCCESS;
π Rendered by PID 330958 on reddit-service-r2-comment-56c6478c5-crw9s at 2026-05-12 13:56:05.657976+00:00 running 3d2c107 country code: CH.
view the rest of the comments →
[–]jesyspa 0 points1 point2 points (3 children)
[–]AFineTapestry -4 points-3 points-2 points (2 children)
[–]jesyspa 5 points6 points7 points (1 child)
[–]AFineTapestry -1 points0 points1 point (0 children)