Must every code have an int main. And why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Must every code have an int main. And why?

17th Nov 2016, 8:48 PM
Cody Arthur
Cody Arthur - avatar
2 Answers
0
HI, The return is normally used by the OS to know what the reason your application end, if you want to inform the application that calls your app OR just return a value to the OS to inform any problem occurred during the execution you can do that by the main return. By default OS uses return 0 for normal END (without error) but you can define your main as VOID MAIN, this means that will be not return anything. BR,
17th Nov 2016, 9:03 PM
Henrique Zenoni Machado
Henrique Zenoni Machado - avatar
0
Yes, every program must have a 'main' function. When the program starts, that function is what is called first: it's the starting point of your program. The 'main' function doesn't have to return an integer though, but that is the convention. Typically that integer represents an error code: different values represent different errors. The 'return 0;' at the end of your 'main' function means that no errors occurred, since you successfully reached the end of your program.
17th Nov 2016, 9:37 PM
Arthur Busser
Arthur Busser - avatar