0

My school always taught to write void main() in C and C++. This is after my high school I found out through this community that you don't write void main() in C++ and C. Does anyone have any idea why schools taught us like that coz honestly now I'm used to writing void main..... (India)

We always used Turbo C++ and it was working fine but when I started to use Visual C++, I got to know this.

Chris
  • 26,361
  • 5
  • 21
  • 42
Adityaaa
  • 19
  • 1
  • Note that `int main()` is mandatory only for a *'hosted environment'* (i.e. the programme is running on an OS) – if you write on bare metal hardware (e.g. micro-controller without OS) this requirement does not apply – entry-point then is implementation (compiler) specific, and there indeed you see `void main()` sometimes (where should a return value go to if there's no OS...). That's not what *you* are coding for, though, not at the moment at least... – Aconcagua Mar 22 '23 at 07:26
  • 6
    *We always used Turbo C++* -- Learning C++ with a compiler from 30 years ago is not progress. It's like teaching modern television repair by using vacuum tubes. – PaulMcKenzie Mar 22 '23 at 07:29
  • 2
    @Adityaaa, maybe you should talk with your teacher or principal of your school about this. – kiner_shah Mar 22 '23 at 07:30
  • 1
    You can safely throw that knowledge away though void main is not completely useless in today's world. But of course Turbo c++ is dead. – digito_evo Mar 22 '23 at 07:32
  • 1
    The short answer is because the teacher (or whoever organised the subject/curriculum) doesn't properly know C or C++. `void main()` is a *non-standard* extension supported by some compilers. Some compiler vendors and some (mostly poor quality) introductory texts incorrectly documented `void main()` as being standard, and some people learning - including some who are now teachers - never looked further than that (stayed with one compiler, one book on the language, etc). While there are high-quality teachers, it is also sometimes true that "those who cannot do, teach". – Peter Mar 22 '23 at 08:01
  • 3
    It has to be lazy or incompetent teachers. Why? Because even Turbo C++, back 30 years ago, accepted `int main()`. It should not have taken a lot of effort for these teachers to just read up on basic C++, and just mention "use int main(), not void main()". But no, their incompetence, laziness, lack of awareness, or some combination of those three things is why you were taught "void main()". – PaulMcKenzie Mar 22 '23 at 08:10

1 Answers1

8

The obvious answer is that they're using outdated teaching materials. The use of Turbo C++ when freely available, modern, open source compilers exist (and have for quite some time) supports that conclusion.

Chris
  • 26,361
  • 5
  • 21
  • 42