+ 1
Whats the significance of void main()?
how is void main() different from int main() and with whom should I use return0?
3 odpowiedzi
+ 7
`void` means that `main` does not return anything, it is simply a procedure (executed step by step).
`int` means that `main` returns an integer, so not only it is a procedure but it also returns something back when the execution terminates. This is the case where you would put `return 0;` at the end of your program (it means the program executed without errors).
The datatype that appears at the start of a function signature (i.e. `int square(int n)`) means that the function must return something of that datatype (except for `void`, in that case there is no `return` statement).
+ 5
There are at least 50 more threads talking about void main. I'm sure we'll clean that up someday, but for now, just know thay void return type for main should never be used in C/C++, because it has never been part of the standard.
https://isocpp.org/wiki/faq/newbie#main-returns-int
http://www.stroustrup.com/bs_faq2.html#void-main
+ 1
"Never say never..."
Long time ago in a galaxy far-far away called MS DOS there lived a compiler Borland Turbo C. RAM was 512k (kilobytes ), and arguments to main function was limited by 128 characters. In those bright times "main" used to be "void".
https://archive.org/stream/bitsavers_borlandturReferenceGuide1988_19310204/Turbo_C_Version_2.0_Reference_Guide_1988_djvu.txt