Return type of main function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Return type of main function?

Is it necessary to have return type of main function as int (and not void)? Why does the code show a compilation error? https://code.sololearn.com/czUK2qE6vJyq/?ref=app https://code.sololearn.com/czUK2qE6vJyq/?ref=app

10th Jun 2019, 3:56 PM
Chetan Satpute
Chetan Satpute - avatar
2 Answers
+ 3
if the code returns a 0, it means the code compiled succesfully and if it returns a -1 it means the code had a error, and if the main is a void it cant give a return value. correct me if im wrong
10th Jun 2019, 4:06 PM
Cat Sauce
Cat Sauce - avatar
+ 1
In C++, returning an integer from the main function is necessary.
10th Jun 2019, 4:06 PM
Seb TheS
Seb TheS - avatar