Loading
submit to reddit
May 22, 2013, 01:03:44 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome!
 
   Forum Home   Help Search Forum Login Register  
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: Difference between main and void?  (Read 571 times)
yohomes
Newbie
*
Posts: 1


« on: August 09, 2011, 12:30:38 AM »

Im watching the C++ video tutorials and at first he started out using int main () { to start the program but switches to void main () { whats the difference between the two?

Also how does he get the console window staying up without the cin get () statement?
Logged
Haitam
Newbie
*
Posts: 16


« Reply #1 on: August 09, 2011, 04:02:46 AM »

The diffrence between Void and Int , is that the Void function doesn't return a value While the int returns,
it is more likely to use as the main function the void, but if you use the int , then you should put a returning value in the last row of the function.
Regarding to Keeping the window open you can use "_getch();" function.
Hope That I helped.
Have a nice DAY.
Logged
Michael Hall
Administrator
Hero Member
*****
Posts: 901



« Reply #2 on: August 09, 2011, 10:20:50 AM »

"void" is only usable with Microsoft's compiler. Since many people were using other compilers, I switched to "int," which is valid on all compilers since it is standard for C++. Initially, I used "void" because I thought it would be easier than having to explain the "return" statement to beginning programmers. This was the only non-standard C++ that I used, and now I avoid it entirely.

To keep the console window open, you can compile with using the "Start Without Debugging" option by pressing (F5 + Ctrl). Microsoft had that option in the menu until 2010 (you can still get it by selecting "Expert Settings" under the "Tool" in the menubar). Since Microsoft took that option out of the menu, I started to use cin.get(). Since this question was so common and has several facets, I created a blog post for it:

http://xoax.net/blog/keeping-the-c-console-window-open/

Mike
Logged
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!