It is not syntactically correct, but maybe not why you expect.
The C++ standard says that programs' main function shall (must) return int.
3.6.1 Main function [basic.start.main]
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. All implementations shall allow both of the following definitions of main: int main() { /* ... */ }
and int main(int argc, char* argv[]) { /* ... */ }
In other words: void main() is wrong.
BobMorane wrote:
Yeah, if you add at a minimum:
1 2
return 0;
}
after the declaration of b
Unique among all functions returning non-void, C++'s main function does not require a return statement.
3.6.1 Main function [basic.start.main]
If control reaches the end of main without encountering a return statement, the effect is that of executing return 0;