Re: int main() / void main()
The explanation is quite simple. int main is the only correct way to declare main because that's what the language standard says.
Re: int main() / void main()
Re: int main() / void main()
Quote:
Originally Posted by
Codeplug
thanks, i copied some lines:
Code:
Actually, main can be declared in any of the four following ways:
int main()
int main(void)
int main(int argc, char *argv[])
int main(int argc, char** argv)
Unless a program uses command-line arguments, one of the first two would suffice.
i've created a program with many functions with: void function(){} The above lines say unless a program uses command-line argumentes int main and int main(void) will be enough.
i use some user_input in my functions and all my functions are like: void function()
so what about:
int main(int argc, char *argv[])
int main(int argc, char** argv)
Re: int main() / void main()
??
int main(int argc, char *argv[])
int main(int argc, char** argv)
are for handling command line arguments. You know there's a difference between command line args and user input?
Re: int main() / void main()
Quote:
Originally Posted by
Amleto
??
int main(int argc, char *argv[])
int main(int argc, char** argv)
are for handling command line arguments. You know there's a difference between command line args and user input?
well never used it that way (yet)
Re: int main() / void main()
Because the standard dictates that every C/C++ program must return a value to indicate its success. It also says that a program must return either 0 or EXIT_SUCCESS if the execution was successful. Declaring main() as void doesn't mean the program won't return a value -- it just means that the value it returns will probably not be 0.
And that's bad because now the operating system thinks that the execution failed. Other horrible things can happen, too.
A bit of searching found that.
in simple terms it says main()has to return 0 or EXIT_SUCCESS to show the program has run successfully and void will not let the return of a proper value that is needed
Re: int main() / void main()
Quote:
Originally Posted by
medicalsalt
Because the standard dictates that every C/C++ program must return a value to indicate its success. It also says that a program must return either 0 or EXIT_SUCCESS if the execution was successful. Declaring main() as void doesn't mean the program won't return a value -- it just means that the value it returns will probably not be 0.
And that's bad because now the operating system thinks that the execution failed. Other horrible things can happen, too.
A bit of searching found that.
in simple terms it says main()has to return 0 or EXIT_SUCCESS to show the program has run successfully and void will not let the return of a proper value that is needed
This was very helpfull, thanks.