What is the difference in int main(void) and no return 0; and int main() with return 0; ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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?

3rd Jun 2020, 11:19 PM
Christina Hamblin
Christina Hamblin - avatar
7 Answers
+ 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!
4th Jun 2020, 1:55 PM
Christina Hamblin
Christina Hamblin - avatar
+ 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.
4th Jun 2020, 2:37 AM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
+ 1
int main () and int main (void) aren't the same as you can see
5th Jun 2020, 11:33 AM
Bye
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.
4th Jun 2020, 1:51 AM
Christina Hamblin
Christina Hamblin - avatar
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";
7th Jun 2020, 8:57 PM
Joseph Israel
Joseph Israel - avatar
- 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.
3rd Jun 2020, 11:40 PM
Michi
Michi - avatar
- 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/
4th Jun 2020, 12:06 AM
Kireii
Kireii - avatar