Why do we have to return 1 in int main() function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

Why do we have to return 1 in int main() function?

18th Oct 2016, 9:14 AM
Lara
Lara - avatar
2 Answers
+ 14
return n is equivalent to exit n. return 0 means the program succeeded, return different from 0 means the program exited due to error or anomaly. If you exit with a status different from 0 you're supposed to print an error message to stderr.
18th Oct 2016, 9:58 AM
Nelli
Nelli - avatar
+ 1
If your fucntion declaration is int or what ever variable , you must put return . If you dont want to put return , use void main() , this function returns noting
6th Nov 2016, 6:33 PM
Nikola Petkovic
Nikola Petkovic - avatar