Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Adding a data type as a function parameter

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;
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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[] ) {
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading