Search⌘ K
AI Features

The Return Value of main( )

Explore how the main() function in D programming returns an exit status code to the operating system. Understand the significance of return values like zero for success and nonzero for errors, and see how to specify custom return codes. Learn about standard error output and how it relates to program termination status.

We have seen that main() is a function. Program execution starts with main() and branches off to other functions from there. The definition of main() that we have used so far has been the following:

void main() {
    // ...
}

According to that definition main() does not take any parameters and does not return a value. In reality, in most systems, every program necessarily returns a value to its environment when it ends, which is called an exit status or return code. Because of this, although it is possible to specify the return type of main() as void, ...