0
What is the difference in int main(void) and no return 0; and int main() with return 0; ?
I understand that return 0; is to return a 0 if your program is correctly executed and anything else if not. Does main(void) do the same or is it meant for something different?
13 ответов
+ 3
The question is for C language, not C++. I am trying to learn C first. The knowledge will come in handy for C++ when I move on to it. So, Thanks everyone for the help. I don't have anyone to teach me and I am on my own. I am eager to learn everything I can. U guys are great!
+ 2
coffeeunderrun To expand on your expansion, just because the compiler will add it in, doesn't mean you should omit it. That's just bad programming practice.
+ 1
int main () and int main (void) aren't the same as you can see
0
Thank you guys very much! I understand the differences much better now. Also Thank you Marina Vss for clearing up "return 0". I wasnt sure if they were connected or not.
0
I am a beginner. C++
How can I write a program that makes me to chose which one of block of code I want to go for
Char a;
Char b;
cout <<" input a for addition or input b for subtraction"<<endl;
cout<<"type a"<<endl;
cout <<"type b"<<endl;
cin>>a, b
If(a)
cout <<"okay";
else
cout<<"wrong input";
- 1
int main() and int main(void) is equal. The void just specifies , that there is no parameter.
For the return value, as it is declared as INT main(..) it should return a int. 0 typically means it ran successfully, others indicate an error. You could specify different return values for different errors.
- 1
First let me clear that “main(void)” is the same as “main()”
The only difference between those two is that the “void” keyword inside main clearly specifies that main has no parameters. Basicaly though its just a formality.
Now as about “return 0” or not, that is not related with “main()” or “main(void)” in any way at all.
The only thing you’d want to note about “return 0” is that since main is of int type, then “return” can only return ( :D) a value of int type (and not ANYTHING else).
“return 0” signifies succesfull execution and “return 1” unsuccesfull.
All in all, “return” as a command is what u’d call the “exit status” of a program, while the content of the parenthesis of “main” is related to its parameters.
https://www.geeksforgeeks.org/difference-int-main-int-mainvoid/