Why we are entering intmain() we can use voidmain() | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why we are entering intmain() we can use voidmain()

8th Dec 2016, 3:32 PM
viknesh
5 Answers
+ 5
Before down voting my answer you should check it your self. No, you cannot use void main it is not supported in new compilers. if you use void main in new compiler like c++11 you will get error. It is depend upon you to go with c++ comunity or not. They did for us then why not use it. In later releases was to notify error occurred in program during execution to operating system on which it running. So, now this is standard that main function should be int type. Hope it help you
8th Dec 2016, 3:55 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 1
If you use void means you don't have to add return statement in main function Now its compiler's duty to add flag that if program was successfull or not. The return value is the exit code of your program, the shell (or any other application that ran it) can read and use it. The 0 exit code (return 0) is a widely accepted convention for 'OK the program execution was successfull' , So it is good practice to use int main().
19th Feb 2018, 1:48 PM
Abhineet Singh
Abhineet Singh - avatar
0
Because void main dosen't return data but int main does return data
8th Dec 2016, 3:42 PM
Nathan
Nathan - avatar
0
yes you can
8th Dec 2016, 3:43 PM
rita swari
rita swari - avatar
0
But if you use void main, you have to erase return 0;
8th Dec 2016, 3:44 PM
Nathan
Nathan - avatar