Is it compulsory to write int main instead of void main while recursion? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is it compulsory to write int main instead of void main while recursion?

29th Oct 2018, 12:57 AM
Sai Swaraj
Sai Swaraj - avatar
4 Answers
+ 4
main function by standard does return int, old compilers may accept main to return void, but it's just non-standard. And although it is possible, it is not considered a good design to have a code that enters main function recursively, one can design a loop within main to repeat a certain task rather than calling the main again to go round and round. Further detailed explanation can be followed on these links: https://stackoverflow.com/questions/204476/what-should-main-return-in-c-and-c https://www.codesdope.com/blog/article/int-main-vs-void-main-vs-int-mainvoid-in-c-c/
3rd Nov 2018, 9:47 AM
Ipang
+ 3
At least identify which language in "Relevant Tags" to prevent confusions for those who wants to respond. Thanks ...
29th Oct 2018, 4:06 AM
Ipang
0
I don't think so. Write int if it's returning an integer or void if it returns nothing.
29th Oct 2018, 2:20 AM
Шащи Ранжан
Шащи Ранжан - avatar
0
Ipang it's 'C' so please give it ans .
3rd Nov 2018, 1:58 AM
Sai Swaraj
Sai Swaraj - avatar