0

I am new to programming. Just have a quick question. What a difference between int main() and just a main(). Because in my book example, the author didn’t write int in a program and when I wrote that program in a codeblock. I was asked to put int main() and program ran. Thanks

  • 3
    That book is probably just old. Either that or the author didn't bother keeping up with the times, which reflects poorly on them. Either way, try to get a better book. – StoryTeller - Unslander Monica May 09 '18 at 12:58
  • 1
    Short, simplified answer: anything but `int main (void)` is incorrect. `int main()` is obsolete style (will compile but not recommended) and `main()` is withdrawn obsolete style (will not compile). For details check the linked duplicate. – Lundin May 09 '18 at 12:59
  • 1
    That's a little restrictive, @Lundin. Of course `int main(int argc, char *argv[])` and equivalents are also explicitly allowed by the standard (for hosted implementations), and all implementations are explicitly permitted to support other implementation-defined signatures, with some common ones in fact doing so. – John Bollinger May 09 '18 at 13:04
  • @StoryTeller can you please recommend the best book? – Rayo Grg May 09 '18 at 13:04
  • It's been a while since I read an introductory book on C. So I can't really recommend anything. We used to have a dedicated FAQ on SO about this very topic, but it has since fallen into disrepair, and should probably not be consulted. – StoryTeller - Unslander Monica May 09 '18 at 13:07
  • @JohnBollinger Hence "simplified answer" /--/ "For details check the linked duplicate". – Lundin May 09 '18 at 13:24
  • @StoryTeller The C book recommendation list was deleted as per [this meta](https://meta.stackoverflow.com/questions/355588/the-c-book-list-has-gone-haywire-what-to-do-with-it). We couldn't come up with a way to repair it and keep it actively maintained, so the community consensus was to delete it. – Lundin May 09 '18 at 13:29

0 Answers0