What is the difference between the main function with a data type vs one with no parameters?
int main(void) {
cout << "File " << endl;
}
int main() {
cout << "File " << endl;
}
CodePudding user response:
Don't quote me as per the standards but what I see is that the only requirement for main is that it needs to return an int. Other than that, the parameters are pretty much open.
As main is considered a function with C linkage, the only thing it needs is really to have the name "main". For example, this works on GCC:
#include <cstdint>
extern "C" int main( int argc, char* argv[], int bogus, int bogus2 ) {
return argc;
}
However on clang it requires 0, 2 or 3 parameters as any of these are valid:
int main() {
}
int main(void) {
}
int main( int argc, char* argv[] ) {
}
int main( int argc, char* argv[], char* env[] ) {
}