[SOLVED] Can the main function be declared before is defined?

Issue

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.

Solution

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.

Answered By – dbush

Answer Checked By – Cary Denson (BugsFixing Admin)

Leave a Reply

Your email address will not be published.