Main function type

Why do we write int main instead of char main or bool main?

Last edited on
Hello zavkk,

Because the language is designed to return an "int" and not some other type.

Ansy
It is expected that any process will return an integer to the operating system, to indicate its completion status. The normal convention is that a return value of 0 indicates success, and a non-zero value indicates some kind of error or unusual status. An application isn't forced to use that convention, and can use that number for other purposes, although it can be annoying for people using it if it doesn't follow the convention (e.g. Robocopy, which uses a completely different convention).
Why do we write int main

The short answer, is because the C++ standard requires main() to return int.
https://stackoverflow.com/questions/449851/why-do-we-need-to-use-int-main-and-not-void-main-in-c
If the program is used within something like a batch/script file, then the returned value can be checked and different action taken depending upon its value.
Topic archived. No new replies allowed.