This has nothing to do with the operating system, it has to do with the compiler. It is probably using Microsoft VC++ on Windows and GCC on Linux. In fact it may even depend on configuration.
Have compiler who can decide that a function always has a return
of the implicit specified type if you do not put something. You have a compiler that requires being explicit to avoid exiting the function in an unwanted way. As the specification says nothing about it neither forcing nor forbidding, each does as he wishes.
This holds true for any function, the fact that it is in the main()
is just a coincidence. So as the main()
was declared a return int
, there will always be a return of 0 if nothing is explicitly returned. Note that the main()
nor need to be called by the operating system, it is a common function.
Generally it is more readable and avoids bugs write the return explicitly, but in the case of main()
and is something simple I do not see major problems, even more in exercises, I have avoided.
My teacher could not explain it to me, I also searched on forums and found nothing relative. I thank you very much for your reply, you have taken away a question I had a long time ago. I’m new around here so I’m sorry if I asked the question improperly.
– Henrique Marques
It’s all right. Try to study from various sources and understand why things are. You’re on the right track by not conforming to "things are like this".
– Maniero