0

Why we write "int" before writing main()

I see all places have something written before main(), like "void", "int"

3rd Aug 2017, 4:38 PM
Subhasish Ghosh
Subhasish Ghosh - avatar
3 ответов
+ 2
This is because main() is still a function, and like all C++ functions, requires a return type. Typically, that is int or void, but it's recommended to use int so you can end the program early if necessary.
3rd Aug 2017, 4:40 PM
Keto Z
Keto Z - avatar
+ 2
It's the result code for the parent process. Usually this is the operating system executor.
3rd Aug 2017, 4:48 PM
Kirk Schafer
Kirk Schafer - avatar
+ 1
1) "void main" is not (and never was) standard C. Use only "int main" 2) You can end the program early even if you use "void main" :)) . But... don't use it :) 3) The return code goes back to the parent process (the one that actually launched your program)
3rd Aug 2017, 7:33 PM
Bogdan Sass
Bogdan Sass - avatar