#include <iostream>
usingnamespace std;
int main()
{
return 0; // Could be return(0)
}
And here is another!
1 2 3 4 5 6 7
#include <iostream>
usingnamespace std;
int main(
{
// No return statement...
}
So, to me, both programmes work the same way! Why do both have different structures! What is the difference between int main() and void main()... And most importantly, which one is better???
I must mention that come compilers don't recognize void main() and return an error that main should compulsorily return an integer!
Please enlighten me! Especially I would like to direct this question to @Bazzy! He has always helped me on standards issue! But everyone else id invited to comment as well... In case this question is too dumb, do let me know :)
Could also be return !!0;
or return ~15;
because both of those would evaluate to all zeros (15 being 1111b; ~15 being 0b).
I'm not so sure about the bitwise ~ though.
Isn't this because void main() returns a random byte to whatever called it but int main() returns '0' when the program finishes w\o errors? Also because some processes that might call your program might also be waiting for a value to indicate that your program finished?
Isn't this because void main() returns a random byte
No. void functions by definition return nothing. Not random data. Just nothing.
Also because some processes that might call your program might also be waiting for a value to indicate that your program finished?
The return value from main() is only used in shell scripting.
1. The script is designed around the programs it uses. If a program is known to not return anything meaningful, then the script should of course not use this value.
2. You can tell that a program finished because the script continues execution.
1 2
function();
//oh noes! how does i know function() returned???