+ 3
[Question] Reason for void() and main() [Solved]
So in c++ ,we use void() and main() in several incidents...so I just wanna know the actual reason for including it..and when do we includ it..
4 Respostas
+ 3
+ 1
When our program is simple, and it is not going to terminate before reaching the last line of the code, or the code is error free, then we can use the void main(). But if we want to terminate the program using exit() method, then we have to return some integer values (zero or non-zero). In that situation, the void main() will not work. So it is good practice to use int main() over the void main().
For more refer:- https://www.tutorialspoint.com/difference-between-void-main-and-int-main-in-c-cplusplus#:~:text=When%20our%20program%20is%20simple,zero%20or%20non%2Dzero).
https://stackoverflow.com/questions/636829/difference-between-void-main-and-int-main-in-c-c
+ 1
C++ standard recommendation is to use `int` as return type for main function.
https://en.cppreference.com/w/cpp/language/main_function