In this code:
int main(int a, int b)
{
printf(" main(int, int) works \n\n");
return 0;
}
the signature of main is main(int, int), and it compiles successfully. Why?
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.
Because the C standard doesn’t prohibit non-standard signatures for
main(see e.g. section 5.1.2 of the C99 standard).However, you’ll find that if you compile under GCC with the
-Wallflag,1 it will complain:It assumes that you want to interact with a standard environment (i.e. process command-line parameters and return an exit status), in which case you must use
int main(int, char **)orint main(void). If you use anything else, the contents of the arguments will be undefined.1. I really wish ideone.com would allow you to specify compiler flags!