Why does main function return 0. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why does main function return 0.

22nd Jun 2016, 4:24 AM
Himanshu singh Bisht
Himanshu singh Bisht - avatar
7 Answers
+ 4
Main function returns 0 to give a signal to underlying operating system that the function main which is called from the OS is passing test without errors...
22nd Jun 2016, 11:02 AM
Nikola Dedović
+ 1
Because all functions return a value to the function that called it to show that it was successful and that there are no errors.
22nd Jun 2016, 9:22 AM
Benny
Benny - avatar
+ 1
It's some kind of programmers agreement. When program do his work, it must be ended properly. When system see that output value is different that 0, then program probably has ended with error (not always, sometime programmer using that for other purpose )
12th Jul 2016, 9:56 AM
Dominik Kulik
Dominik Kulik - avatar
0
Its the starting point of a code and executes it and its a special type of function meaning "main" is a type of methos that will tell c++ to start there at the main function.
23rd Jun 2016, 2:02 AM
Jabari Laforest
Jabari Laforest - avatar
0
return type of main is integer
23rd Jun 2016, 7:54 PM
Zuber Ahmed
Zuber Ahmed - avatar
- 1
because we are taking main function's data type as int , so every data type returns valu except void
22nd Jun 2016, 6:03 PM
Yash Modi
Yash Modi - avatar
- 1
Also it returns 0 because the function void main returns nothing because it hases void in it and that means it doesnt return a value until you write code in it, and soon when you call that function, that code within it will execute
23rd Jun 2016, 8:09 PM
Jabari Laforest
Jabari Laforest - avatar