is not and never has been C++, nor has it even been C. See the ISO C++ standard 3.6.1 or the ISO C standard 22.214.171.124.1. A conforming implementation accepts
A conforming implementation may provide more versions of main(), but they must all have return type int. The int returned by main() is a way for a program to return a value to “the system” that invokes it. On systems that doesn’t provide such a facility the return value is ignored, but that doesn’t make “void main()” legal C++ or legal C. Even if your compiler accepts “void main()” avoid it, or risk being considered ignorant by C and C++ programmers.
In C++, main() need not contain an explicit return statement. In that case, the value returned is 0, meaning successful execution.
Note also that neither ISO C++ nor C99 allows you to leave the type out of a declaration. That is, in contrast to C89 and ARM C++ ,”int” is not assumed where a type is missing in a declaration.
This above code has no error. If you write the whole error-free main() function without return statement at the end then compiler automatically add return statement with proper datatype at the end of the program.
To summarize above, it is never a good idea to use “void main()” or just “main()” as it doesn’t confirm standards. It may be allowed by some compilers though.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Write a C program to print "Geeks for Geeks" without using a semicolon
- Write a one line C function to round floating point numbers
- Write a C macro PRINT(x) which prints x
- Write one line functions for strcat() and strcmp()
- When should we write our own copy constructor?
- Does C++ compiler create default constructor when we write our own?
- When should we write our own assignment operator in C++?
- Write a C program that does not terminate when Ctrl+C is pressed
- fopen() for an existing file in write mode
- Write a C program that won't compile in C++
- Write a program that produces different results in C and C++
- How to write a running C code without main()?
- Write your own memcpy() and memmove()
- Write a URL in a C++ program
- lseek() in C/C++ to read the alternate nth byte and write it in another file
- Write a C program that displays contents of a given file like 'more' utility in Linux
- How to write long strings in Multi-lines C/C++?
- Write your own strlen() for a long string padded with '\0's
- Input-output system calls in C | Create, Open, Close, Read, Write
- Read/Write structure to a file in C
Improved By : sudhanshu29gupta