difference between return 0 and retuen -1

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prathap rudra
    New Member
    • Oct 2013
    • 3

    difference between return 0 and retuen -1

    difference between return 0 and return -1 .and exit(0) and exit(1)
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Return values are just made up. many programmers return 0 to indicate the function completed successfully. This leaves all the other integer values to mean what kind of failure occurred.

    Functions doing compares between two arguments A and B might return:

    0 means A == B
    1 means A > B
    -1 means A < B

    Functions returning pointers usually return 0 if the function fails since a 0 pointer is always invalid. A non-zero return is assumed to be a valid address.

    In the case of main() and exit() the 0 means a successful end of the program and -1 means the program terminated in error. There is no access to this value outside the program so it's just there for the programmer to see in the code.

    Comment

    Working...