+ 2

Why we write as 'return 0' at the end of the code? Even though I write as return 1 or return 100 or return 1000 it gets executed

I get same output in all the cases then why we prefer writing as return 0 only at the end, we can also return other positive numbers right

13th Oct 2017, 4:18 PM
Manikanta
Manikanta - avatar
4 Antworten
+ 11
Important note: As program success or failure can only be determined after execution has completed, changing the return value of main when using sololearns compiler is in effect useless. As you will never see or be able to do anything with any error message the operating system may return.
13th Oct 2017, 5:03 PM
jay
jay - avatar
+ 2
The return value can be used by the calling program to decide what it does next. There still are places out there that do check it so you would be wise to return 0.
13th Oct 2017, 4:59 PM
John Wells
John Wells - avatar