What is the correct way, according to the latest C standard, to define functions without parameters: int main() or int main(void)?
What is the correct way, according to the latest C standard, to define functions
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Both forms of definition are valid (the one without
voidis an invalid prototype and an incomplete (albeit valid) declaration).The form
int main(void) { /* whetever */ }also provides a prototype for the function.The form
int main() { /* whatever */ }does not provide a prototype (and the compiler cannot check if it is called correctly).See the Standard (PDF)
difference between definition:
int main() { /* whatever */ }and declaration:
int main();and prototype:
int main(void);.The definition does not provide a prototype;
the declaration is valid but specifies no information about the number or types of parameters;
the prototype is ok and compatible with the definition.