This is likely a stupid question but I always find myself wondering which is the standard.
In most (not to say all) C++ first examples you may see the main function returning 0 value. This means the operation went ok or not?
- 0 –> OK
- 1 –> No OK.
- Other –> ?
Which is the standard way of doing it?
By the way, is it better to return an integer or a boolean in this case?
Thank you guys!
0orEXIT_SUCCESSmeans success.EXIT_FAILUREmeans failure. Any other value is implementation defined, and is not guaranteed to be supported. In particular,std::exit(1)orreturn 1;are not actually guaranteed to indicate failure, although on most common systems they will.EXIT_SUCCESSandEXIT_FAILUREare defined in<cstdlib>.Edit: I suppose it might be useful to give a system-specific example:
The GNU make utility returns an exit status to the operating system:
The ability to set multiple different values of failure means you can specify exactly how your program failed. There are two caveats, however: