Home > OS >  Can the main function be declared before is defined?
Can the main function be declared before is defined?

Time:02-20

I know that the main function is just a "special" function, but can it be declared and then defined like any other function or not?

This is also correct :

int main(void);

int main(void) {

}

or just this is correct :

int main(void) {

}

?

P.S. I know that when a function is defined is automatically declared, but I didn't know how to formulate this question better.

CodePudding user response:

It's fine to create a declaration for the main function (provided it matches the definition).

It just won't be of any use because nothing else in your program calls main, or at least it shouldn't.

  • Related