Thread: what is 'return 0'

  1. #1
    Registered User
    Join Date
    Aug 2011
    Location
    Dhaka, Bangladesh, Bangladesh
    Posts
    4

    what is 'return 0'

    i am a new member. just started c programming. please tell me what is 'return 0'or
    'return 1'.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    The return result from main is used to tell the environment whether the program was successful (or not).

    Code:
    $ cat foo.c && gcc foo.c && ./a.out ; echo "Process exit status = " $?
    #include<stdio.h>
    
    int main( void ) {
      return 0;
    }
    Process exit status =  0
    
    
    $ cat foo.c && gcc foo.c && ./a.out ; echo "Process exit status = " $?
    #include<stdio.h>
    
    int main( void ) {
      return 1;
    }
    Process exit status =  1
    0 always means success, as does the constant EXIT_SUCCESS. EXIT_FAILURE denotes a failure, and any other numeric constant is dependent on your OS / environment.

    Use ERRORLEVEL in DOS command.com / Win32 cmd.exe
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 07-04-2007, 12:20 AM
  2. Replies: 12
    Last Post: 04-07-2007, 11:11 AM
  3. Replies: 6
    Last Post: 04-09-2006, 04:32 PM
  4. Replies: 4
    Last Post: 07-15-2005, 04:10 PM
  5. Return Return Error
    By javacvb in forum C++ Programming
    Replies: 8
    Last Post: 12-16-2003, 04:17 PM

Tags for this Thread