Possible Duplicate:
What should main() return in C/C++?
Just started coding C about an hour ago, after a few months of basic java coding, and am encountering a problem compiling the basic hello world program.
Here is my code:
#include < stdio.h>
void main()
{
printf("\nHello World\n");
}
and this is what i get back when i try to compile:
Hello.c: In function ‘main’:
Hello.c:13: warning: return type of ‘main’ is not ‘int’
any help would be much apprecated, thanks!
The standard signatures for main
are either
int main(void)
or
int main(int argc, char **argv)
Your compiler is simply enforcing the standard.
Note that an implementation may support void main()
, but it must be explicitly documented, otherwise the behavior is undefined. Like dandan78 says, a large number of books and online references get this wrong.
it should be
int main() {}
then you should return 0
if the program is terminating correctly or any other number if there was an error. That's an Unix convention, so scripts can check if the program was terminated correctly or an error occurred.
main-function in c has to return an int:
#include < stdio.h>
int main()
{
printf("\nHello World\n");
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With