+ 2

Fundamental Question on C

What is the difference between int main() and int main(void)

6th Feb 2018, 7:28 AM
RAJESH SINHA
RAJESH SINHA - avatar
4 Answers
+ 9
In C++, no difference. Void in parameters is a relic from C. In C, when we do int main(), nothing is specified regarding the parameters. int main(void), on the other hand, tells the compiler that this main function takes no arguments. https://stackoverflow.com/questions/5587207/why-put-void-in-params https://stackoverflow.com/questions/693788/is-it-better-to-use-c-void-arguments-void-foovoid-or-not-void-foo
6th Feb 2018, 8:08 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
@Mohd Zaki The int at the beginning of int main() and int main(void) is what makes it return an integer. The parameters make no difference there.
6th Feb 2018, 11:12 AM
Jacob Pembleton
Jacob Pembleton - avatar
+ 3
in plain c int main(void); is a function decleration that takes no arguments int main(); is a prototype that can take yet unspecified number of arguments in c++ there is no difference. Further i dont see any use in prototyping the main function...
6th Feb 2018, 8:20 AM
---
--- - avatar
- 6
int main() will return a int value but int main(void) do not return anything.
6th Feb 2018, 7:39 AM
Mohd Zaki
Mohd Zaki - avatar