RSS Forums RSS
Please support our C advertiser: Programming Forums

simple query about cout

Join Date: Sep 2004
Posts: 6,565
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 497
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: simple query about cout

  #7  
Apr 7th, 2005
>Nothing was returned
Standard C++ returns 0 by default. Returning from main can be tricky, especially if you switch languages and work with legacy code a lot. In pre-standard C++ you need to explicitly return a value. In C89 you need to explicitly return a value. In standard C++ and C99, you can omit the return value and 0 will be returned automagically.

However, because C99 isn't widely implemented yet, everyone follows the intersection of C89 and C99 to avoid nonportable code during the interrim of changing from old standard to new standard. Since standard C++ is well implemented now, it's safe to omit the return value, but many still do it explicitly anyway as a matter of style and consistency.

My preference is to omit the return value unless I return failure, then I return success explicitly as well:
int main()
{
  // Don't return anything explicitly
}
#include <cstdlib>

using namespace std;

int main()
{
  if ( some_failure )
    return EXIT_FAILURE; // Return failure here

  return EXIT_SUCCESS; // And success here
}
>don't you have to put something inside the braces?
No, an empty block is legal. It's roughly equivalent to:
if ( something )
  ;
But that uses a semicolon, so it's not a valid solution for the problem.
I'm here to prove you wrong.
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 4:45 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC