+ 3
[solved] Why this error?
I used return type of main() as void but in code playground it gives an error saying main() should return int. But if I do same thing in 'C' there is no error Is it ide dependent or what???? https://code.sololearn.com/c53YRXjZrdn0/?ref=app https://code.sololearn.com/cM2jpH71rVoe/?ref=app
2 Antworten
+ 4
By the standard, `main` must be declared as one of
int main()
or
int main(int argc, char *argv[])
or equivalent.
So, `void main()` is not standard C or C++. In C++ it is just plain illegal, and C allows "other implementation-defined" ways of declaring `main`. Some C compilers support `void main()` and some don't.
Long story short: Use `int`, everything else is illegal/nonstandard. It is shorter to write too so there is no reason not to.
+ 4
Thanks Schindlabua 🙂👍