void main()
Thursday 18 July 2002
I was puzzled by Ingve's comment on my sample code in the entry on Koenig lookup. It turns out that according to the C++ standard main() must always return int. However most compilers also support void, contrary to the standard which only allows:
int main()
or
int main(int argc, char* argv[])
I used void main() to save a line of code in the sample. However I could have used int main() without a return statement because this is allowed by the standard: if execution falls off the end of main(), it is treated as though a "return 0;" was the last statement. Therefore the following program is valid C++:
#include <stdio.h>
int main()
{
puts("Hello world");
}
Posted by
at 10:30 AM.
Permalink.
Copyright © Charles Cook.
Valid XHTML 1.0