Main function type

Apr 26, 2021 at 6:05pm
Why do we write int main instead of char main or bool main?

Last edited on Apr 26, 2021 at 6:05pm
Apr 26, 2021 at 6:20pm
Hello zavkk,

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

Ansy
Apr 26, 2021 at 8:21pm
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).
Apr 26, 2021 at 8:37pm
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
Apr 27, 2021 at 10:03am
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.