0
When to use void main() and when to use int main()
In c programing
4 ответов
+ 1
As long as you are in a hosted environment (one that has the standard library available for you), which is usually always the case, you should follow the standard.
And, as far as the standard is concerned, there are two valid signatures for the main() function of your program:
int main( void );
int main( int argc, char* argv[] );
There is some room open for a user defined implementation, but it has to be equivalent to one of the latter, for example int can be replaced by a typedef name defined as int, or
int main();
is essentially the same as (1) and therefore also okay.
However, the signature
void main();
is not standard C inside a hosted environment.
Please refer:
https://stackoverflow.com/questions/2108192/what-are-the-valid-signatures-for-cs-main-function/
https://stackoverflow.com/questions/204476/what-should-main-return-in-c-and-c
https://stackoverflow.com/questions/636829/difference-between-void-main-and-int-main
0
When you want to return type int from the function use int main() when the function don't returning nothing use void main().
0
Though not really necessary to put anything it's still a good practice..
If you put void main() you don't need a return statement
And if you put any other data type like int the main function must return (not necessarily) a value.. like:
return 0;
0
Please also specify the language in Relevant Tags 👍