Solved

difference between int main( ) and int main (void)

Posted on 2002-07-12
3
1,011 Views
Last Modified: 2010-05-18
is there a difference between int main( ) and int main (void)?
0
Comment
Question by:mitchguy
  • 2
3 Comments
 

Accepted Solution

by:
poclea earned 50 total points
ID: 7149183
There is no difference. The compiler automatically replaces a int main() declaration with int main(void).
0
 

Author Comment

by:mitchguy
ID: 7149729
When I had a C++ class a few years ago the lab assistant
said there was a difference, but didn't want to go into the details since it might add confusion to someone who is just learning. It just recently occured to me that I never found out what the difference was. I believe that there is a difference. Or at least there must be more to it than that.
0
 

Author Comment

by:mitchguy
ID: 7149783
I think I found the information I was looking for and since this is a c++ forum your answer is accuarate.
I found the following explanation in a help tutorial

A function prototype with an empty parameter list, such as
    extern void func();

means in C that the argument list of the declared function is not prototyped: the compiler will not be able to warn against improper argument usage. When declaring a function in C which has no arguments, the keyword void is used, as in:
    extern void func(void);

Because C++ enforces strict type checking, an empty parameter list is interpreted as the absence of any parameter. The keyword void can then be omitted: in C++ the above two declarations are equivalent.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now