what is int main in c language

what is int main in c language

1 year ago 97
Nature

In C programming language, the main() function is the starting point of program execution. It is a user-defined function that marks the beginning of the program execution and is critical to the programs execution. The main() function can have a return type of int or void .

  • int main(): This means that the function needs to return some integer at the end of the execution, and we do so by returning 0 at the end of the program. 0 is the standard for the “successful execution of the program” .

  • void main(): This is an old-style declaration that indicates main() takes an unspecified number of arguments. The ANSI standard says "no" to the void main() and thus using it can be considered wrong.

  • int main(void): This means that the function takes no arguments. In C, a function without any parameter can take any number of arguments. For example, a function declared as foo() can take any number of arguments in C.

In C++, int main() and int main(void) are the same. Although it doesn’t make any difference most of the times, using int main(void) is a recommended practice in C.

In summary, int main() and int main(void) are both valid ways to define the main() function in C, but int main(void) is considered technically better as it clearly specifies that the main() can only be called without any parameter.

Read Entire Article