[solved] Why this error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

1st Oct 2019, 8:58 AM
Arsenic
Arsenic - avatar
2 Answers
+ 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.
1st Oct 2019, 9:08 AM
Schindlabua
Schindlabua - avatar
+ 4
Thanks Schindlabua 🙂👍
1st Oct 2019, 9:10 AM
Arsenic
Arsenic - avatar