+ 2

Why i got message "main must return int"?

i've try to run this code: void main(){ //blablabla } and got message "main must return int", Why it's happen?

29th Jun 2018, 1:18 PM
sherlockholmes
sherlockholmes - avatar
5 ответов
+ 5
Please use the search bar to search for threads which may answer to your query, to avoid posting duplicate threads. https://www.sololearn.com/Discuss/1225/?ref=app
29th Jun 2018, 2:45 PM
Hatsy Rei
Hatsy Rei - avatar
+ 5
in c this is a warning main() { } In c++ this is error main() { }
29th Jun 2018, 3:03 PM
Arun Tomar
Arun Tomar - avatar
+ 4
With C++ and C, the main function must be declared as an int, and therefore must return an int. In your code, you had changed the main function to a void, returning an error. Try changing void main() to int main() and add a line at the end of your function that returns 0. int main(){ statement(s) return 0; }
29th Jun 2018, 1:22 PM
Faisal
Faisal - avatar
+ 1
main requiring a return type of int couldn't possibly be the answer could it?
29th Jun 2018, 4:00 PM
hinanawi
hinanawi - avatar
+ 1
It's necessary for main() function to return an integral value (0) to operating system because it checks the number to verify that the program has run successfully or not . If it returns a value 0 it has ran successfully or any other value means it contains a problem int main() { // }
30th Jun 2018, 9:23 AM
Aveek Bhattacharyya
Aveek Bhattacharyya - avatar