error about main() in playground console | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

error about main() in playground console

#include <iostream> using namespace std; void main(void) { cout << "Hello world!" << endl; cout << "I love programming!"; } why can't playground console run the void main() block ? the main() must be int class and return int number?

13th Apr 2017, 3:47 AM
Chain Leang
Chain Leang - avatar
4 Answers
+ 8
use int main () not void main(void) Use void for a message inside a class. Copy this for void to work. https://code.sololearn.com/cx5hj7AO1856/?ref=app
13th Apr 2017, 3:49 AM
Manual
Manual - avatar
+ 5
The error message is pretty explicit: "error: '::main' must return 'int'" As it says, the main function must return an integer as this is part of the C++ standard. While some compilers will ignore it (they'll automatically add a return value of 0 to your program), it's technically incorrect. The reason you return anything to begin with is to indicate to the operating system that the program either executed successfully (0), or ran into an error (anything else).
13th Apr 2017, 3:53 AM
Squidy
Squidy - avatar
+ 2
according to new rules of c++ there are some changes in it's standards. now you can't use void data type as main function you must use int as data type. so new compilers show error when void is used
13th Apr 2017, 4:01 AM
Sandeep Chatterjee
+ 1
Yes, the main function must return an int. The reason is to give useful signals to the caller (system) when the program is terminated.
13th Apr 2017, 3:52 AM
Denis Felipe
Denis Felipe - avatar