+ 4
Why do we write int before main?
9 odpowiedzi
+ 10
Adding to what Aksita G said. Return value of main is used as exit code of the program. If your program executed without any errors then it returns 0 otherwise error code is returned.
So in C++ it is illegal to declare main as void, according to latest C++ standards
+ 6
Try using search bar to search for similar questions first ,before posting a new question.
https://www.sololearn.com/discuss/1918381/?ref=app
https://www.sololearn.com/discuss/81360/?ref=app
https://www.sololearn.com/discuss/44133/?ref=app
https://www.sololearn.com/discuss/1225/?ref=app
https://www.sololearn.com/discuss/80763/?ref=app
https://www.sololearn.com/discuss/1896258/?ref=app
+ 5
The main() function takes arguments, and returns some value. The program starts executing from this main() function. So the operating system calls this function. When some value is returned from main(), it is returned to operating system
The void main() indicates that the main() function will not return any value, but the int main() indicates that the main() can return integer type data.
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 to use int main() over the void main().
+ 3
Aditya rout actually 0 is for successfull execution. And if the program have error in it then it returns it's error code. If there would have been only 2 possibilities then return type would have been Boolean instead of integer.
+ 2
It's the return type of the main function.
0
•Because the main function returns type integer,i.e either '1/program ran successfully' or '0/program compile error '.
•The massage is returned by the ' return ' object of 'ostream ' class.
- 1
In C language only main is used and in C++ int main() is used...