Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Difference between void main() & int main & void main(void)
Closed Thread
Old 12-01-2004, 12:51 PM   #1 (permalink)
 
Newb Techie

Join Date: Nov 2004

Posts: 38

DemonEdge

Default Difference between void main() & int main & void main(void)

Hi,
In my c++ cs classes we use void main() only
but all the tutorials outhere have int main()
what is the difference?
and what is return @ the end of the code??
i never use return and my programs work good
DemonEdge is offline  
Old 12-01-2004, 12:58 PM   #2 (permalink)
 
Ultra Techie

Join Date: Jun 2004

Posts: 973

intercodes

Send a message via Yahoo to intercodes
Default

DemonEdge,

'void main()' specifies that the main function does not return any value.
'int main()' specifies that main fn returns an integer value at the end of the function to the Operating system.

IF you use int main , you should use a 'return' function at the end along with an integer value. Thou it is not compulsory to use a return statement, you will be specified with the warning during compilation.

The reason behind using int main and return is to specify the OS that the program executed successfully. The OS assumes that program executed successfully only by knowing the return value of the function. So a 'return 0' value indicates successful execution. anyother integer value than 0 indicates there's been problem with the problem.
intercodes is offline  
Old 12-01-2004, 01:07 PM   #3 (permalink)
 
Newb Techie

Join Date: Nov 2004

Posts: 38

DemonEdge

Default

Thanks for the very fast reply man.
that means that IF i use void main() the OS won't know if the program ended successfully or not?
IF yes then...to **** with OS i don't need it to know

now to the second thing
how is void main() different from void main(void)?
DemonEdge is offline  
Old 12-01-2004, 01:19 PM   #4 (permalink)
 
Ultra Techie

Join Date: Jun 2004

Posts: 973

intercodes

Send a message via Yahoo to intercodes
Default


DemonEdge,

Quote:
how is void main() different from void main(void)?
Every function takes up null/any number of parameters. 'void main()' indicates implicitly that it takes no parameters. 'void main(void)' -explicit null parameter declaration.
I guess there is no other difference for that...

intercodes is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On