UrbanPro
true

Learn C++ Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Is It Fine To Write “void main()” Or “main()” In C/C++?

Sunil Yadav
13/07/2017 0 2

The definition:

void main() { /* ... */ }

Is not and never has been C++, nor has it even been C. See the ISO C++ standard 3.6.1[2] or the ISO C standard 5.1.2.2.1. A conforming implementation accepts

int main() { /* ... */ }
 
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. Consequently:

#include
 
main() { /* ... */ }

is an error because the return type of main() is missing.

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.

0 Dislike
Follow 3

Please Enter a comment

Submit

Ashutosh Singh | 16/12/2017

Always write 'void main()' or 'int main()'. In the latter case, the last line of your main function should be ' return 0;'

0 1

Rajat Kiran Mahapatro | 24/10/2017

depending on the type of value we return from our program we mention the return type ... so both are correct

0 1

Other Lessons for You

All About Programming And A Good Programmer.
Hi, This is my first lesson for you guys. Hope you enjoy reading it. In recent community questions, I found many people wanted to be good programmers, or wanted to have good hands on certain language,...

Operators in C
Operators in C Operator: An operator is a symbol that tells the compiler to perform certain mathematical or logical calculations. Operators are used in programs to manipulate data and variables. The...

Memory Layout Of C Program
1. Text or Code Segment: Text segment contains machine code of the compiled program. Usually, the text segment is sharable so that only a single copy needs to be in memory for frequently executed programs,...

Do You Know Size Of Empty Class and Reason?
Size of empty class is always 1 byte. Reason is, in order to differentiate one object to another object, the size of empty class is always 1 byte. See the below c++ code snippet. Here there are three...

Predict the Output of C Questions based on Recursion and Macro
#include<stdio.h>void k(unsigned int i,unsigned int j){ static char x="0123456789ABCDEF"; if(i>=j) k(i/j,j); putchar(x);}void main(){ k(20,12);} ___________________________________________ ...
X

Looking for C++ Language Classes?

The best tutors for C++ Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C++ Language with the Best Tutors

The best Tutors for C++ Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more