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 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!
+ 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/