About the main() function

I believe it’s where all functions get really called. The program won’t execute any of them out of the main() section, unless they get called in main().

I’m also very curious, why int, not other variable types?

As far as I know, you could use other types. It all depends on whether what you return from main (in our examples, ‘0’) will be used by another program to check whether your program completed successfully or not.

I think you can delete the “int” and delete the line that says “return 0” and the compiler will assume it to be void.

I think the only point to keep to that tradition, is to help other programs to evaluate the success of yours. And you could have different return values, for instance 1 or -1 to signal errors. But that’s more advanced and probably won’t be needed at all here.

1 Like

Privacy & Terms