Why would you precede the main() function in C with a data type?
Posted
by Milktrader
on Stack Overflow
See other posts from Stack Overflow
or by Milktrader
Published on 2010-05-23T17:54:40Z
Indexed on
2010/05/23
18:00 UTC
Read the original article
Hit count: 195
c
|best-practices
Many are familiar with the hello world program in C
#include <stdio.h>
main ()
{
printf ("hello world");
return 0;
}
Why do some precede the main () function with int as in:
int main()
Also, I've seen the word 'void' entered inside the () as in:
int main(void)
It seems like extra typing for nothing, but maybe it's a best practice that pays dividends in other situations?
Also, why precede main() with an int if you're returning a character string? If anything, one would expect:
char main(void)
I'm also foggy about why we return 0 at the end of the function.
© Stack Overflow or respective owner