by Ives · 15y ago · 0 comments
#include "stdio.h"
void main()
{
printf( "Hello world!\n" );
getchar();
}
- main() should return int, not void- std::cout should be used instead of printf
- std::cin should be used instead of getchar()
Edit: I must be tired: this is a tutorial on C++, and thus should use C++ style. Also, despite the old-style windows, this article is quite new.
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 otherwise
its type is implementation-defined.
But note: 5 A return statement in main has the effect of leaving
the main function (destroying any objects with auto-
matic 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;
The other two points I disagree with. =P- No
- No
And you didn't even complain about "stdio.h".
Compilers care, or should. "void main" is illegal per the spec, and if your compiler happens to do anything useful with that, it's purely out of luck.