what is 'return 0'

This is a discussion on what is 'return 0' within the C Programming forums, part of the General Programming Boards category; i am a new member. just started c programming. please tell me what is 'return 0'or 'return 1'....

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 03:17 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21