Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,091 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,578 people online right now. Registration is fast and FREE... Join Now!




Question

 
Reply to this topicStart new topic

Question

Sp3ke
1 Oct, 2007 - 10:53 PM
Post #1

New D.I.C Head
*

Joined: 1 Oct, 2007
Posts: 1


My Contributions
I'm currently a new C++ programmer, and I was just curious about the following.

What's the different between

CODE
int main()
//and
int main(void)


Is there a difference?

Thanks,


Sp3ke
User is offlineProfile CardPM
+Quote Post

nirvanarupali
RE: Question
1 Oct, 2007 - 11:39 PM
Post #2

D.I.C Foot
Group Icon

Joined: 1 Aug, 2007
Posts: 983



Thanked: 2 times
Dream Kudos: 375
My Contributions
Your answer is HERE
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Question
2 Oct, 2007 - 12:22 AM
Post #3

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 11 times
My Contributions
Actually the answer is not there,
but here (near the bottom)
User is offlineProfile CardPM
+Quote Post

marklon
RE: Question
2 Oct, 2007 - 11:47 PM
Post #4

New D.I.C Head
*

Joined: 2 Oct, 2007
Posts: 3


My Contributions
QUOTE(Sp3ke @ 1 Oct, 2007 - 11:53 PM) *

I'm currently a new C++ programmer, and I was just curious about the following.

What's the different between

CODE
int main()
//and
int main(void)


Is there a difference?

Thanks,


Sp3ke

yes

User is offlineProfile CardPM
+Quote Post

gaurav_sharma132
RE: Question
3 Oct, 2007 - 07:13 AM
Post #5

New D.I.C Head
*

Joined: 27 Sep, 2007
Posts: 2


My Contributions
hi smile.gif ,there is no difference b/w the two.Basically,main is a function and function may have parametres or may not have.if it doesnt have parametres then its txt in bracket is empty.AND VOID REPRESENT EMPTY.it is mandatory to write void.
User is offlineProfile CardPM
+Quote Post

jjhaag
RE: Question
3 Oct, 2007 - 11:43 AM
Post #6

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
no, there is a difference. this is directly from the site in 1lacca's post:

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

A common misconception for C programmers, is to assume that a function prototyped as follows takes no arguments:

int foo();

In fact, this function is deemed to take an unknown number of arguments. Using the keyword void within the brackets is the correct way to tell the compiler that the function takes NO arguments.


if you don't believe it, whip up two programs, one with int main() and one with int main(void), and compare them with a file comparison tool. they will not be the same (i've checked - gcc-3.4.5).

-jjh
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 08:19PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month