Can't we use 'void main()' as the main function as we do in c language? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can't we use 'void main()' as the main function as we do in c language?

I just ran a Hello world program inside the void main() function. But it gave me an error saying void must return 'int'

19th Oct 2017, 2:55 AM
Matheesha Yapa
Matheesha Yapa - avatar
1 Answer
+ 6
No, void main is an incorrect syntax, thus, returns an error. void main, was never C++. The int is necessary to return the exit code to the operating system for successful termination. https://www.sololearn.com/discuss/784887/?ref=app https://www.sololearn.com/discuss/791548/?ref=app
19th Oct 2017, 3:46 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar