- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What should main() return in C and C++?
- The return value for main is used to indicate how the program exited. If the program execution was normal, a 0 return value is used. Abnormal termination(errors, invalid inputs, segmentation faults, etc.) is usually terminated by a non-zero return. There is no standard for how non-zero codes are interpreted.
- You can define your own status codes though and use them to represent different types of failures in the program.
- GCC recommends using either EXIT_SUCCESS or EXIT_FAILURE defined in stdlib.h for sending exit signals.
- In C++, int main() can be left without a return value at which point it defaults to returning 0.
- Related Articles
- What should main() return in C/C++?
- return statement vs exit() in main() C++
- Return Statement vs Exit() in Main() using C++
- Difference between void main and int main in C/C++
- Difference between “int main()” and “int main(void)” in C/C++?
- C/C++ difference's between "int main()" and "int main(void)"
- Differentiate between int main and int main(void) function in C
- What is the main difference between int.Parse() and Convert.ToInt32 in C#?
- What is the proper declaration of main in C++?
- What are copy elision and return value optimization in C++?
- Valid variant of Main() in C#
- Can main() be overloaded in C++?
- What are the main parts of a C# program?
- Functions that are executed before and after main() in C
- Function overloading and return type in C++

Advertisements